Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

This looks maybe useful #3

Open
wants to merge 18 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
10 changes: 10 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ Changelog

Here you can see the full list of changes between each Flask-OAuthlib release.

Version 0.9.6
-------------

Released on Sept 7, 2020

- Fix dependency conflict with requests-oauthlib
- Fix imports for Werkzeug


Version 0.9.5
-------------

Expand All @@ -12,6 +21,7 @@ Released on May 16, 2018
- Update supported OAuthlib
- Add support for string type token


Version 0.9.4
-------------

Expand Down
Empty file added README.md
Empty file.
38 changes: 13 additions & 25 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ Flask-OAuthlib
:target: https://coveralls.io/r/lepture/flask-oauthlib
:alt: Coverage Status


Notice
------

**You SHOULD use https://github.com/lepture/authlib instead**.

=====

Flask-OAuthlib is an extension to Flask that allows you to interact with
remote OAuth enabled applications. On the client site, it is a replacement
for Flask-OAuth. But it does more than that, it also helps you to create
Expand All @@ -33,21 +32,23 @@ Flask-OAuthlib relies on oauthlib_.

.. _oauthlib: https://github.com/idan/oauthlib


Sponsored by
------------

If you want to quickly add secure authentication to Flask, feel free to
check out Auth0's Python API SDK and free plan at `auth0.com/overview`_
check out Auth0's Python API SDK and free plan at `auth0.com/developers`_
|auth0 image|

.. _`auth0.com/overview`: https://auth0.com/overview?utm_source=GHsponsor&utm_medium=GHsponsor&utm_campaign=flask-oauthlib&utm_content=auth
.. _`auth0.com/developers`: https://auth0.com/developers?utm_source=GHsponsor&utm_medium=GHsponsor&utm_campaign=flask-oauthlib&utm_content=auth

.. |auth0 image| image:: https://user-images.githubusercontent.com/290496/31718461-031a6710-b44b-11e7-80f8-7c5920c73b8f.png
:target: https://auth0.com/overview?utm_source=GHsponsor&utm_medium=GHsponsor&utm_campaign=flask-oauthlib&utm_content=auth
:target: https://auth0.com/developers?utm_source=GHsponsor&utm_medium=GHsponsor&utm_campaign=flask-oauthlib&utm_content=auth
:alt: Coverage Status
:width: 18px
:height: 18px


Features
--------

Expand All @@ -58,10 +59,6 @@ Features
- Support OAuth1 provider with HMAC and RSA signature
- Support OAuth2 provider with Bearer token

And request more features at `github issues`_.

.. _`github issues`: https://github.com/lepture/flask-oauthlib/issues


Security Reporting
------------------
Expand All @@ -73,25 +70,16 @@ Attachment with patch is welcome.
Installation
------------

Installing flask-oauthlib is simple with pip_::
Installing flask-oauthlib is simple with pip::

$ pip install Flask-OAuthlib

If you don't have pip installed, try with easy_install::

$ easy_install Flask-OAuthlib

.. _pip: http://www.pip-installer.org/


Additional Notes
----------------

We keep documentation at `flask-oauthlib@readthedocs`_.
There is also a `development version <https://github.com/lepture/flask-oauthlib/archive/master.zip#egg=Flask-OAuthlib-dev>`_ on GitHub.

.. _`flask-oauthlib@readthedocs`: https://flask-oauthlib.readthedocs.io

If you are only interested in the client part, you can find some examples
in the ``example`` directory.
Links
-----

There is also a `development version <https://github.com/lepture/flask-oauthlib/archive/master.zip#egg=Flask-OAuthlib-dev>`_ on GitHub.
- Documentation: https://flask-oauthlib.readthedocs.io
- PyPI: https://pypi.org/project/Flask-OAuthlib/
- Client Examples: https://github.com/lepture/flask-oauthlib/tree/master/example
2 changes: 1 addition & 1 deletion docs/oauth1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ To implemente the oauthorization flow, we need to understand the data model.
User (Resource Owner)
---------------------

A user, or resource owner, is usally the registered user on your site. You
A user, or resource owner, is usually the registered user on your site. You
design your own user model, there is not much to say.


Expand Down
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.5"

__version__ = "10.0.0"
__author__ = "Hsiaoming Yang <[email protected]>"
__homepage__ = 'https://github.com/lepture/flask-oauthlib'
__license__ = 'BSD'
5 changes: 3 additions & 2 deletions flask_oauthlib/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
from functools import wraps
from oauthlib.common import to_unicode, PY3, add_params_to_uri
from flask import request, redirect, json, session, current_app
from werkzeug import url_quote, url_decode, url_encode
from werkzeug import parse_options_header, cached_property
from werkzeug.urls import url_quote, url_decode, url_encode
from werkzeug.http import parse_options_header
from werkzeug.utils import cached_property
from .utils import to_bytes
try:
from urlparse import urljoin
Expand Down
4 changes: 2 additions & 2 deletions flask_oauthlib/contrib/cache.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding: utf-8

from werkzeug.contrib.cache import NullCache, SimpleCache, FileSystemCache
from werkzeug.contrib.cache import MemcachedCache, RedisCache
from cachelib import NullCache, SimpleCache, FileSystemCache
from cachelib import MemcachedCache, RedisCache


class Cache(object):
Expand Down
2 changes: 1 addition & 1 deletion flask_oauthlib/provider/oauth1.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import logging
from functools import wraps
from werkzeug import cached_property
from werkzeug.utils import cached_property
from flask import request, redirect, url_for
from flask import make_response, abort
from oauthlib.oauth1 import RequestValidator
Expand Down
50 changes: 33 additions & 17 deletions flask_oauthlib/provider/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +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 werkzeug import cached_property
from werkzeug.utils import import_string

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 @@ -155,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 @@ -413,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 @@ -438,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 @@ -462,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 @@ -471,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 @@ -502,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 @@ -545,6 +552,7 @@ def token_handler(self, f):
def access_token():
return None
"""

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

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

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

return decorated

return wrapper


Expand All @@ -624,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 @@ -674,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 @@ -901,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 <[email protected]>"]
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
Loading