diff --git a/README.md b/README.md new file mode 100644 index 00000000..e69de29b diff --git a/flask_oauthlib/__init__.py b/flask_oauthlib/__init__.py index a8d492e3..b5a3b256 100644 --- a/flask_oauthlib/__init__.py +++ b/flask_oauthlib/__init__.py @@ -11,7 +11,8 @@ :license: BSD, see LICENSE for more details. """ -__version__ = "0.9.6" + +__version__ = "10.0.0" __author__ = "Hsiaoming Yang " __homepage__ = 'https://github.com/lepture/flask-oauthlib' __license__ = 'BSD' diff --git a/flask_oauthlib/provider/oauth2.py b/flask_oauthlib/provider/oauth2.py index 14a57af2..d212c85b 100644 --- a/flask_oauthlib/provider/oauth2.py +++ b/flask_oauthlib/provider/oauth2.py @@ -8,17 +8,23 @@ :copyright: (c) 2013 - 2014 by Hsiaoming Yang. """ -import os -import logging import datetime +import logging +import os from functools import wraps -from flask import request, url_for + from flask import redirect, abort + +from flask import request, url_for + from werkzeug.utils import import_string, cached_property + from oauthlib import oauth2 +from oauthlib.common import add_params_to_uri from oauthlib.oauth2 import RequestValidator, Server -from oauthlib.common import to_unicode, add_params_to_uri -from ..utils import extract_params, decode_base64, create_response +from werkzeug.utils import import_string, cached_property + +from ..utils import extract_params, create_response __all__ = ('OAuth2Provider', 'OAuth2RequestValidator') @@ -154,10 +160,10 @@ def validate_client_id(self, client_id): ) if hasattr(self, '_clientgetter') and \ - hasattr(self, '_tokengetter') and \ - hasattr(self, '_tokensetter') and \ - hasattr(self, '_grantgetter') and \ - hasattr(self, '_grantsetter'): + hasattr(self, '_tokengetter') and \ + hasattr(self, '_tokensetter') and \ + hasattr(self, '_grantgetter') and \ + hasattr(self, '_grantsetter'): usergetter = None if hasattr(self, '_usergetter'): @@ -412,6 +418,7 @@ def authorize(*args, **kwargs): confirm = request.form.get('confirm', 'no') return confirm == 'yes' """ + @wraps(f) def decorated(*args, **kwargs): # raise if server not implemented @@ -437,7 +444,7 @@ def decorated(*args, **kwargs): state = request.values.get('state') if state and not e.state: e.state = state # set e.state so e.in_uri() can add the state query parameter to redirect uri - return self._on_exception(e, e.in_uri(redirect_uri)) + return self._on_exception(e, e.in_uri(self.error_uri)) except Exception as e: log.exception(e) @@ -461,7 +468,7 @@ def decorated(*args, **kwargs): state = request.values.get('state') if state and not e.state: e.state = state # set e.state so e.in_uri() can add the state query parameter to redirect uri - return self._on_exception(e, e.in_uri(redirect_uri)) + return self._on_exception(e, e.in_uri(self.error_uri)) if not isinstance(rv, bool): # if is a response or redirect @@ -470,9 +477,10 @@ def decorated(*args, **kwargs): if not rv: # denied by user e = oauth2.AccessDeniedError(state=request.values.get('state')) - return self._on_exception(e, e.in_uri(redirect_uri)) - + return self._on_exception(e, e.in_uri(self.error_uri)) + return self.confirm_authorization_request() + return decorated def confirm_authorization_request(self): @@ -501,7 +509,7 @@ def confirm_authorization_request(self): return self._on_exception(e, e.in_uri(self.error_uri)) except oauth2.OAuth2Error as e: log.debug('OAuth2Error: %r', e, exc_info=True) - + # on auth error, we should preserve state if it's present according to RFC 6749 state = request.values.get('state') if state and not e.state: @@ -544,6 +552,7 @@ def token_handler(self, f): def access_token(): return None """ + @wraps(f) def decorated(*args, **kwargs): server = self.server @@ -554,6 +563,7 @@ def decorated(*args, **kwargs): uri, http_method, body, headers, credentials ) return create_response(*ret) + return decorated def revoke_handler(self, f): @@ -573,6 +583,7 @@ def revoke_token(): .. _`RFC7009`: http://tools.ietf.org/html/rfc7009 """ + @wraps(f) def decorated(*args, **kwargs): server = self.server @@ -586,10 +597,12 @@ def decorated(*args, **kwargs): ret = server.create_revocation_response( uri, headers=headers, body=body, http_method=http_method) return create_response(*ret) + return decorated def require_oauth(self, *scopes): """Protect resource with specified scopes.""" + def wrapper(f): @wraps(f) def decorated(*args, **kwargs): @@ -610,7 +623,9 @@ def decorated(*args, **kwargs): return abort(401) request.oauth = req return f(*args, **kwargs) + return decorated + return wrapper @@ -623,6 +638,7 @@ class OAuth2RequestValidator(RequestValidator): :param grantgetter: a function to get grant token :param grantsetter: a function to save grant token """ + def __init__(self, clientgetter, tokengetter, grantgetter, usergetter=None, tokensetter=None, grantsetter=None): self._clientgetter = clientgetter @@ -673,6 +689,7 @@ def client_authentication_required(self, request, *args, **kwargs): .. _`Section 4.1.3`: http://tools.ietf.org/html/rfc6749#section-4.1.3 .. _`Section 6`: http://tools.ietf.org/html/rfc6749#section-6 """ + def is_confidential(client): if hasattr(client, 'is_confidential'): return client.is_confidential @@ -900,7 +917,7 @@ def validate_code(self, client_id, code, client, request, *args, **kwargs): log.debug('Grant not found.') return False if hasattr(grant, 'expires') and \ - datetime.datetime.utcnow() > grant.expires: + datetime.datetime.utcnow() > grant.expires: log.debug('Grant is expired.') return False diff --git a/install-poetry.sh b/install-poetry.sh new file mode 100644 index 00000000..5b2e7f03 --- /dev/null +++ b/install-poetry.sh @@ -0,0 +1,20 @@ +venv/Scripts/python -m ensurepip --upgrade +venv/Scripts/python -m pip install pip setuptools wheel -U +venv/Scripts/python -m pip install -r requirements.txt -U + +venv/Scripts/python -m pip install poetry twine -U +# +venv/Scripts/poetry config repositories.pypiserver https://pypiserver.thinktalentws48.click/simple/ +venv/Scripts/poetry config http-basic.pypiserver devops 13972684 +venv/Scripts/poetry source add --secondary pypiserver https://pypiserver.thinktalentws48.click/simple/ +venv/Scripts/poetry config http-basic.pypiserver devops 13972684 +venv/Scripts/poetry config --list +venv/Scripts/poetry config virtualenvs.in-project true +#venv/Scripts/poetry run pip install -r requirements.txt +# +# +#rm -rf build/ dist/ encryption_util.egg-info/ +#venv/Scripts/python -m build +##venv/Scripts/poetry build +##venv/Scripts/poetry publish --repository pypiserver +#twine upload -r local --username devops --password 13972684 --repository-url https://pypiserver.thinktalentws48.click dist/* \ No newline at end of file diff --git a/install.sh b/install.sh new file mode 100644 index 00000000..80dd9b48 --- /dev/null +++ b/install.sh @@ -0,0 +1,11 @@ +venv/Scripts/python -m ensurepip --upgrade +venv/Scripts/python -m pip install pip setuptools wheel -U +venv/Scripts/python -m pip install -r requirements.txt -U +venv/Scripts/python -m pip install twine -U +venv/Scripts/python -m pip list +#venv/Scripts/python -m pip list -o +#venv/Scripts/python -m pip freeze + +rm -rf build/ dist/ encryption_util.egg-info/ +venv/Scripts/python -m build +venv/Scripts/twine upload -r local --username devops --password 13972684 --repository-url https://pypiserver.thinktalentws48.click dist/* \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..1f3c3013 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,26 @@ +[tool.poetry] +name = "flask-oauthlib" +version = "10.0.1" +description = "" +authors = ["Devops "] +readme = "README.md" +packages = [{ include = "flask_oauthlib" }] + +[tool.poetry.dependencies] +python = "^3.10" +oauthlib = "2.0.6" +flask = "^3.0.3" +mock = "^5.1.0" +flask-sqlalchemy = "^3.1.1" +cachelib = "0.1.1" +requests-oauthlib = "^1.3.0" + + +[[tool.poetry.source]] +name = "pypiserver" +url = "https://pypiserver.thinktalentws48.click/simple/" +priority = "secondary" + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" diff --git a/requirements.sh b/requirements.sh new file mode 100644 index 00000000..1a278e6f --- /dev/null +++ b/requirements.sh @@ -0,0 +1,6 @@ +#venv/Scripts/poetry add oauthlib==2.0.6 +#venv/Scripts/poetry add flask +#venv/Scripts/poetry add mock +venv/Scripts/poetry add requests-oauthlib +#venv/Scripts/poetry add Flask-SQLAlchemy +#venv/Scripts/poetry add cachelib==0.1.1 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 47c2c60e..d5628528 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,13 @@ -Flask>=0.12.3 -mock==2.0.0 +# Flask>=0.12.3 +# mock==2.0.0 oauthlib==2.0.6 -requests-oauthlib==0.8.0 -Flask-SQLAlchemy==2.1 + +# requests-oauthlib==0.8.0 +# Flask-SQLAlchemy==2.1 +Flask +mock +# oauthlib +requests-oauthlib +Flask-SQLAlchemy cachelib==0.1.1 +