A simple Outh2 client
Project description
Oauth2 library for python flask and restplus
With this simple library, you can authenticate clients coming from a browser (Implicit Flow) or using Bearer token (Credential flow). You can manage authorization using rbac function as described here after.
Requirements
Install these requirements
cryptography
PyJWT==1.7.1
flask-restplus
simple-oauth2
Usage example
import os
from flask import Flask
from flask_restplus import Api, Resource
from simple_oauth2 import OAuth
api = Api()
app = Flask(__name__)
app.secret_key = os.urandom(32)
api.init_app(app)
oauth_config = {
'well_known_url': '{well_known_url}',
'client_id': '{client_id}',
'redirect_uri': '{host:port}/signin-oidc',
'audience': '{audience}',
'scopes': '{coma separated scopes}',
'whitelist': ['/openbar?']
}
def rbac(client, operation):
print('client ', client, ' is asking for operation ', operation)
return True
oauth = OAuth(app, oauth_config, rbac=rbac)
# flask
@app.route('/')
def slah():
return 'Hello'
@app.route('/hello')
@oauth.authorize('hello')
def hello():
return 'hi'
@app.route('/openbar')
def openbar():
return 'Chimay'
# restplus
@api.route('/toto')
class Toto(Resource):
@oauth.authorize('toto')
def get(self):
return {'hello': 'world'}
if __name__ == "__main__":
app.run(host='0.0.0.0', debug=True)
Contributors
Register here
Install required packages
python -m pip install --user --upgrade setuptools wheel
python -m pip install --user --upgrade twine
Package like this:
python setup.py sdist bdist_wheel
python -m twine upload --repository-url https://test.pypi.org/legacy/ dist/*
Test install
pip install -i https://test.pypi.org/simple/ simple-oauth2
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file simple_oauth2-1.0.4.tar.gz.
File metadata
- Download URL: simple_oauth2-1.0.4.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc979f3876562a7adcfc15a7df06e1bd76a66be79eb23f259875851fae1a649b
|
|
| MD5 |
922a90e18d775cc093c3fa12395acfec
|
|
| BLAKE2b-256 |
82a7db1e87b3605de3670b2536c35d99c884b174f628035295d6efa8e1604c6d
|
File details
Details for the file simple_oauth2-1.0.4-py3-none-any.whl.
File metadata
- Download URL: simple_oauth2-1.0.4-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd372e40a009b8343b5dd562a1e39ae7653f3a2fc5a37ea152b69a9490817b9a
|
|
| MD5 |
44dac9ba280002a6d22aa57683ab0312
|
|
| BLAKE2b-256 |
4b9f9dc087c008de45720dfed3107b30bf1a6c5ace281292632c0f485c6fdcd6
|