Coder Social home page Coder Social logo

simple_oauth2's Introduction

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': '{space 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

simple_oauth2's People

Contributors

aminebizid avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.