Skip to content

Commit

Permalink
global: import and package fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Jiri Kuncar <[email protected]>
  • Loading branch information
jirikuncar committed Dec 2, 2015
1 parent 9784ad9 commit ac97ed2
Show file tree
Hide file tree
Showing 46 changed files with 1,951 additions and 153 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ charset = utf-8
[*.py]
indent_size = 4
# isort plugin configuration
known_third_party = invenio_accounts,invenio_db
known_first_party = invenio_oauth2server
multi_line_output = 2
default_section = THIRDPARTY
Expand Down
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,13 @@ script:

after_success:
- coveralls

deploy:
provider: pypi
user: jirikuncar
password:
secure: xSD/XcMnmhBYRqcJbLOPsIFDhMCV48EaeLwNkGW0sQPlTsgm1PtIm6eyedogq2gaKJsOoan20mc1VH4L0P2AGiLuAvuxXUpjr/Zj/QePJ8iCeLoy5Tg1I8VfkUQsBtO9lIRtqg5qUI5u8w6PhfAOXB9JqoBOv5WHpE/zir5fvMKwSG/K8nlk3JD+C3Hi3gWgcdIsr/BPpeB+lqqh4dLVQSDz+42aH553IMCCgZpiXEmQ9w9/IdeUZCHMZgFNyz4HQbxQIXx8SLjKmcA/jwbcWCX4WzawJxgnoGH7HcETh9GjNmcRBDbyRLQiG8Um4hyfMoZ87P5om08FfRSvGKce7Wg8bEcZVGrXy/S1H+Ofh2zYG9pQJ7OHF4qqCaw3vhZ2Vo7f5xqv4e7vl3JyukAzpykTYPacad+87Ob8u74dLiO0fszUnhDOyD8MXlbQo8UlOHRL4sdqHTuNGXE0OXMhlvH1+vCzCKEZYu++2BwnYuzll9bt0JCWynyjuD+INAQrns/8YCjVSzgKJ+KjgpNkdoNznUMoBrah/McuAfww5j17FOUNUZVvjcVM24y1zW905poxoiKqJfI+StPYyZ5uv+o9alkAozeCXDrae9awXGKE4JY2jiua+bZQW0WmH9IJ05/ekY9LeB/C4ga05w7bGaxeNhRoJfkcsjANBlRo9zA=
distributions: "compile_catalog sdist bdist_wheel"
on:
tags: true
python: "2.7"
14 changes: 12 additions & 2 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,20 @@
waive the privileges and immunities granted to it by virtue of its status
as an Intergovernmental Organization or submit itself to any jurisdiction.


Authors
=======

Invenio module that implements OAuth 2 server.

- CERN <[email protected]>
- Charlotte Cattaneo <[email protected]>
- Eirini Psallida <[email protected]>
- Esteban J. G. Gabancho <[email protected]>
- Ivan Masár <[email protected]>
- Jiri Kuncar <[email protected]>
- Konstantinos Kostis <[email protected]>
- Lars Holm Nielsen <[email protected]>
- Leonardo Rossi <[email protected]>
- Marco Neumann <[email protected]>
- Roman Chyla <[email protected]>
- Sami Hiltunen <[email protected]>
- Tibor Simko <[email protected]>
44 changes: 42 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,50 @@
waive the privileges and immunities granted to it by virtue of its status
as an Intergovernmental Organization or submit itself to any jurisdiction.


Changes
=======

Version 0.1.0 (released TBD)
Version 1.0.0 (released 2015-02-12)
-----------------------------------

- Refactores package.

Version 0.2.0 (released 2015-10-06)
-----------------------------------

Incompatible changes
~~~~~~~~~~~~~~~~~~~~

- Removes legacy upgrade recipes. You **MUST** upgrade to the latest
Invenio 2.1 before upgrading Invenio-Upgrader.

Bug fixes
~~~~~~~~~

- Removes calls to PluginManager consider_setuptools_entrypoints()
removed in PyTest 2.8.0.
- Adds missing `invenio_base` dependency.

Notes
~~~~~

- Disables test_settings_index test case.

Version 0.1.1 (released 2015-08-25)
-----------------------------------

Improved features
~~~~~~~~~~~~~~~~~

- Marks strings in templates for translations. (#3)

Bug fixes
~~~~~~~~~

- Adds missing `invenio_upgrader` dependency and amends past upgrade
recipes following its separation into standalone package.

Version 0.1.0 (released 2015-08-04)
-----------------------------------

- Initial public release.
26 changes: 18 additions & 8 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,26 @@
# waive the privileges and immunities granted to it by virtue of its status
# as an Intergovernmental Organization or submit itself to any jurisdiction.


# TODO: Generate this manifest file by running the following commands:
#
# git init
# git add -A
# pip install -e .[all]
# check-manifest -u

# Check manifest will not automatically add these two files:
include .dockerignore
include .editorconfig
include .tx/config
recursive-include invenio_oauth2server *.po *.pot *.mo

# added by check_manifest.py
include *.rst
include *.sh
include *.txt
include LICENSE
include babel.ini
include pytest.ini
recursive-include docs *.bat
recursive-include docs *.py
recursive-include docs *.rst
recursive-include docs Makefile
recursive-include examples *.py
recursive-include invenio_oauth2server *.html
recursive-include invenio_oauth2server *.mo
recursive-include invenio_oauth2server *.po
recursive-include invenio_oauth2server *.pot
recursive-include tests *.py
7 changes: 7 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,10 @@ Invenio module that implements OAuth 2 server.

* Free software: GPLv2 license
* Documentation: https://pythonhosted.org/invenio-oauth2server/

Features
========

* Settings view for configuring applications and personal access tokens.
* Uses encryption field for seamless encryption/decryption of the access
and refresh tokens.
8 changes: 4 additions & 4 deletions RELEASE-NOTES.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
=============================
Invenio-OAuth2Server v0.1.0
Invenio-OAuth2Server v1.0.0
=============================

Invenio-OAuth2Server v0.1.0 was released on TBD, 2015.
Invenio-OAuth2Server v1.0.0 was released on TBD, 2015.

About
-----
Expand All @@ -14,12 +14,12 @@ Invenio module that implements OAuth 2 server.
What's new
----------

- Initial public release.
- Refactores package.

Installation
------------

$ pip install invenio-oauth2server==0.1.0
$ pip install invenio-oauth2server==1.0.0

Documentation
-------------
Expand Down
5 changes: 2 additions & 3 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
as an Intergovernmental Organization or submit itself to any jurisdiction.


=======
Usage
=======
Usage
=====

.. automodule:: invenio_oauth2server
3 changes: 0 additions & 3 deletions examples/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,3 @@
app = Flask(__name__)
Babel(app)
InvenioOAuth2Server(app)

if __name__ == "__main__":
app.run()
63 changes: 63 additions & 0 deletions invenio_oauth2server/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2014, 2015 CERN.
#
# Invenio is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# Invenio is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Invenio; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307, USA.
#
# In applying this license, CERN does not
# waive the privileges and immunities granted to it by virtue of its status
# as an Intergovernmental Organization or submit itself to any jurisdiction.

"""OAuth2Server configuration variables."""

OAUTH2_CACHE_TYPE = 'redis'
""" Type of cache to use for storing the temporary grant token """

OAUTH2_PROVIDER_ERROR_ENDPOINT = 'oauth2server.errors'
""" Error view endpoint """

OAUTH2_PROVIDER_TOKEN_EXPIRES_IN = 3600
""" Life time of an access token """

OAUTH2_CLIENT_ID_SALT_LEN = 40
""" Length of client id """

OAUTH2_CLIENT_SECRET_SALT_LEN = 60
""" Length of the client secret """

OAUTH2_TOKEN_PERSONAL_SALT_LEN = 60
""" Length of the personal access token """

OAUTH2_ALLOWED_GRANT_TYPES = [
'authorization_code', 'client_credentials', 'refresh_token',
]
"""
A list of allowed grant types - allowed values are `authorization_code`,
`password`, `client_credentials`, `refresh_token`). By default password is
disabled, as it requires the client application to gain access to the username
and password of the resource owner
"""

OAUTH2_ALLOWED_RESPONSE_TYPES = [
"code", "token"
]
"""
A list of allowed response types - allowed values are `code` and `token`.
- ``code`` is used for authorization_code grant types
- ``token`` is used for implicit grant types
"""
4 changes: 0 additions & 4 deletions invenio_oauth2server/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,12 @@

"""Errors raised by Invenio-OAuth2Server."""

from __future__ import absolute_import, print_function


class OAuth2ServerError(Exception):

"""Base class for errors in oauth2server module."""


class ScopeDoesNotExists(OAuth2ServerError):

"""Scope is not registered it scopes registry."""

def __init__(self, scope, *args, **kwargs):
Expand Down
62 changes: 45 additions & 17 deletions invenio_oauth2server/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,40 +26,68 @@

from __future__ import absolute_import, print_function

import pkg_resources

from . import config
from .models import Scope
from .provider import oauth2


class _OAuth2ServerState(object):
"""OAuth2 server state storing registered scopes."""

def __init__(self, app, entry_point_group=None):
"""Initialize state."""
self.app = app
self.scopes = {}

if entry_point_group:
self.load_entry_point_group(entry_point_group)

def scope_choices(self, exclude_internal=True):
"""Return list of scope choices."""
return [
(k, scope) for k, scope in sorted(self.scopes.items())
if not exclude_internal or not scope.is_internal
]

def register_scope(self, scope):
"""Register a scope."""
if not isinstance(scope, Scope):
raise TypeError("Invalid scope type.")
assert scope.id not in self.scopes
self.scopes[scope.id] = scope

def load_entry_point_group(self, entry_point_group):
"""Load actions from an entry point group."""
for ep in pkg_resources.iter_entry_points(group=entry_point_group):
self.register_scope(ep.load())


class InvenioOAuth2Server(object):
"""Invenio-OAuth2Server extension."""

def __init__(self, app=None):
def __init__(self, app=None, **kwargs):
"""Extension initialization."""
if app:
self.init_app(app)
self.init_app(app, **kwargs)

def init_app(self, app):
def init_app(self, app, entry_point_group='invenio_oauth2server.scopes',
**kwargs):
"""Flask application initialization."""
self.init_config(app)

oauth2.init_app(app)

app.extensions['invenio-oauth2server'] = self
state = _OAuth2ServerState(app, entry_point_group=entry_point_group)
app.extensions['invenio-oauth2server'] = state

def init_config(self, app):
"""Initialize configuration."""
app.config.setdefault(
"OAUTH2SERVER_BASE_TEMPLATE",
app.config.get("BASE_TEMPLATE",
"invenio_oauth2server/base.html"))
app.config.setdefault('OAUTH2_CLIENT_ID_SALT_LEN', 40)
app.config.setdefault('OAUTH2_CLIENT_SECRET_SALT_LEN', 60)
app.config.setdefault('OAUTH2_CACHE_TYPE', 'redis')
app.config.setdefault('OAUTH2_TOKEN_PERSONAL_SALT_LEN', 60)
app.config.setdefault('OAUTH2_PROVIDER_ERROR_ENDPOINT',
'oauth2server.errors'),
app.config.setdefault('OAUTH2_ALLOWED_RESPONSE_TYPES', ['code',
'token'])
app.config.setdefault('OAUTH2_ALLOWED_GRANT_TYPES', [
'authorization_code', 'client_credentials', 'refresh_token',
],)
app.config.setdefault('OAUTH2_PROVIDER_TOKEN_EXPIRES_IN', 3600)

for k in dir(config):
if k.startswith('OAUTH2_'):
app.config.setdefault(k, getattr(config, k))
Loading

0 comments on commit ac97ed2

Please sign in to comment.