Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

need latest code pull #403

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added README.md
Empty file.
3 changes: 2 additions & 1 deletion flask_oauthlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
:license: BSD, see LICENSE for more details.
"""

__version__ = "0.9.6"

__version__ = "10.0.0"
__author__ = "Hsiaoming Yang <me@lepture.com>"
__homepage__ = 'https://github.com/lepture/flask-oauthlib'
__license__ = 'BSD'
47 changes: 32 additions & 15 deletions flask_oauthlib/provider/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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'):
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -544,6 +552,7 @@ def token_handler(self, f):
def access_token():
return None
"""

@wraps(f)
def decorated(*args, **kwargs):
server = self.server
Expand All @@ -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):
Expand All @@ -573,6 +583,7 @@ def revoke_token():

.. _`RFC7009`: http://tools.ietf.org/html/rfc7009
"""

@wraps(f)
def decorated(*args, **kwargs):
server = self.server
Expand All @@ -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):
Expand All @@ -610,7 +623,9 @@ def decorated(*args, **kwargs):
return abort(401)
request.oauth = req
return f(*args, **kwargs)

return decorated

return wrapper


Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
20 changes: 20 additions & 0 deletions install-poetry.sh
Original file line number Diff line number Diff line change
@@ -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/*
11 changes: 11 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -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/*
26 changes: 26 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[tool.poetry]
name = "flask-oauthlib"
version = "10.0.1"
description = ""
authors = ["Devops <devops@thinktalentindia.com>"]
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"
6 changes: 6 additions & 0 deletions requirements.sh
Original file line number Diff line number Diff line change
@@ -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
15 changes: 11 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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