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 8d54b33
Show file tree
Hide file tree
Showing 21 changed files with 190 additions and 69 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.
18 changes: 18 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,21 @@ 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
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
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
"""
2 changes: 0 additions & 2 deletions invenio_oauth2server/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@


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
10 changes: 2 additions & 8 deletions invenio_oauth2server/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,14 @@
from __future__ import absolute_import, print_function

import six

from flask import current_app
from flask_babelex import gettext as _
from flask_login import current_user

from invenio_accounts.models import User
from invenio_db import db

from sqlalchemy_utils.types import URLType
from sqlalchemy_utils.types.encrypted import AesEngine, EncryptedType

from werkzeug.security import gen_salt

from wtforms import validators

from .errors import ScopeDoesNotExists
Expand All @@ -52,7 +47,6 @@ def secret_key():


class NoneAesEngine(AesEngine):

"""Filter None values from encrypting."""

def encrypt(self, value):
Expand All @@ -67,14 +61,12 @@ def decrypt(self, value):


class String255EncryptedType(EncryptedType):

"""String encrypted type."""

impl = db.String(255)


class OAuthUserProxy(object):

"""Proxy object to an Invenio User."""

def __init__(self, user):
Expand Down Expand Up @@ -110,6 +102,7 @@ def get_current_user(cls):

class Scope(object):
"""OAuth scope definition."""

def __init__(self, id_, help_text='', group='', internal=False):
"""Initialize scope values."""
self.id = id_
Expand Down Expand Up @@ -378,6 +371,7 @@ def get_visible_scopes(self):
@classmethod
def create_personal(cls, name, user_id, scopes=None, is_internal=False):
"""Create a personal access token.
A token that is bound to a specific user and which doesn't expire, i.e.
similar to the concept of an API key.
"""
Expand Down
6 changes: 3 additions & 3 deletions invenio_oauth2server/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,18 @@
from flask import current_app
from flask_login import current_user
from flask_oauthlib.provider import OAuth2Provider

from invenio_accounts.models import User
from invenio_db import db

from .models import Token, Client

from .models import Client, Token

oauth2 = OAuth2Provider()


@oauth2.usergetter
def get_user(username, password, *args, **kwargs):
"""Get user for grant type password.
Needed for grant type 'password'. Note, grant type password is by default
disabled.
"""
Expand All @@ -53,6 +52,7 @@ def get_user(username, password, *args, **kwargs):
@oauth2.tokengetter
def get_token(access_token=None, refresh_token=None):
"""Load an access token.
Add support for personal access tokens compared to flask-oauthlib
"""
if access_token:
Expand Down
9 changes: 6 additions & 3 deletions invenio_oauth2server/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +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.

"""Load scopes."""

from __future__ import absolute_import, print_function

from flask_registry import RegistryProxy, DictRegistry, RegistryError
from flask_registry import DictRegistry, RegistryError, RegistryProxy

from .models import Scope


class ScopesRegistry(DictRegistry):

"""Registry for OAuth scopes."""

def register(self, scope):
""" Register an OAuth scope. """
"""Register an OAuth scope."""
if not isinstance(scope, Scope):
raise RegistryError("Invalid scope value.")
super(ScopesRegistry, self).register(scope.id, scope)

def choices(self, exclude_internal=True):
"""Return list of choices."""
items = self.items()
items.sort()
return [(k, scope) for k, scope in items if
Expand Down
1 change: 0 additions & 1 deletion invenio_oauth2server/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

from oauthlib.oauth2.rfc6749.errors import InsecureTransportError, \
InvalidRedirectURIError

from six.moves.urllib_parse import urlparse

from .errors import ScopeDoesNotExists
Expand Down
2 changes: 2 additions & 0 deletions invenio_oauth2server/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
# waive the privileges and immunities granted to it by virtue of its status
# as an Intergovernmental Organization or submit itself to any jurisdiction.

"""Blueprint instances."""

from __future__ import absolute_import, print_function

from .server import blueprint as server_blueprint
Expand Down
Loading

0 comments on commit 8d54b33

Please sign in to comment.