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
Metadata
Release files for simple-oauth2 1.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| simple_oauth2-1.0.4.tar.gz | 4.2 kB | Without provenance | Details for simple_oauth2-1.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| simple_oauth2-1.0.4-py3-none-any.whl | Python 3 | none | any | Details for simple_oauth2-1.0.4-py3-none-any.whl |
Total release size: 9.3 kB
Release files / simple_oauth2-1.0.4.tar.gz
| Download URL | simple_oauth2-1.0.4.tar.gz |
|---|---|
| Size | 4.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bc979f3876562a7adcfc15a7df06e1bd76a66be79eb23f259875851fae1a649b
|
|
BLAKE2b-256 checksum How to use checksums |
82a7db1e87b3605de3670b2536c35d99c884b174f628035295d6efa8e1604c6d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / simple_oauth2-1.0.4-py3-none-any.whl
| Download URL | simple_oauth2-1.0.4-py3-none-any.whl |
|---|---|
| Size | 5.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fd372e40a009b8343b5dd562a1e39ae7653f3a2fc5a37ea152b69a9490817b9a
|
|
BLAKE2b-256 checksum How to use checksums |
4b9f9dc087c008de45720dfed3107b30bf1a6c5ace281292632c0f485c6fdcd6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Security for simple-oauth2 1.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.