Socket
Book a DemoInstallSign in
Socket

flask-oauthprovider

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flask-oauthprovider

A full featured and secure OAuth provider base

0.1.3
pipPyPI
Maintainers
1

Flask-OAuthProvider

Flask-OAuthProvider is an extension that makes it easy to secure your views with OAuth::

@provider.require_oauth()
def user_feed(self):
    ...

It gives you fine grained control over access through the use of realms::

@provider.require_oauth(realm="photos")
def user_photos(self):
    ...

As well as the OAuth parameters such as client key and token::

@provider.require_oauth()
def whoami(self):
    return request.oauth.client_key

Note this extension does NOT give you an OAuth client. For that simply use requests_ which has OAuthLib backed OAuth support built in. If you want to know more about OAuth check out the excellent guide at hueniverse_ or dig into the very readable OAuth 1 RFC 5849 spec_.

.. _requests: https://github.com/kennethreitz/requests .. _hueniverse: http://hueniverse.com/oauth/ .. _OAuth 1 RFC 5849 spec: http://tools.ietf.org/html/rfc5849

Example

Take a look at the example application for a fully working, SQLite / SQLAlchemy backed OAuth provider in the /examples_ folder.

Before running the demo you need to install a few dependencies (virtualenv is highly recommended). This will be replaced by a single line of pip soon...::

$ virtualenv venv
$ source venv/bin/activate
(venv)$ git clone https://github.com/idan/oauthlib.git
(venv)$ python oauthlib/setup.py install
(venv)$ git clone https://github.com/ib-lundgren/flask-oauthprovider.git 
(venv)$ python flask-oauthprovider/setup.py install
(venv)$ pip install flask-openid sqlalchemy

After installing you can run the demo application::

(venv)$ python flask-oauthprovider/examples/runserver.py

Usage

Flask-OAuthProvider builds opon OAuthLib_ and its OAuth 1 RFC 5849 Server_ class. You will need to implement a number of abstract methods, required from either Server (OAuthLib_) or OAuthProvider(Flask-OAuthProvider). These methods are mainly data storage or retrieval methods. No assumptions are made about the persistence system you use and as such you are free to use any you see fit.

While implementing your provider class you want to give OAuthLib Server docs_ and the OAuthProvider source_ a thorough read.

The implementation guide is on its way, feel free to take a look at the overview pictures of how Flask-OAuthProvider and OAuthLib fit into the OAuth workflow.

  • Client registration_
  • Request tokens_
  • Access tokens_
  • Request verification_

When you have hacked together a shiny provider class it will be easy to secure your API with OAuth::

app = Flask(__name__)
provider = YourProvider(app)

@app.route("/my_secrets")
@provider.require(realm="secrets")
def my_secrets(self):
    ...

.. _OAuth 1 RFC 5849 Server: https://github.com/idan/oauthlib/blob/master/oauthlib/oauth1/rfc5849/__init__.py .. _OAuthLib: https://github.com/idan/oauthlib .. _/examples: https://github.com/ib-lundgren/flask-oauthprovider/tree/master/examples .. _OAuthLib Server docs: https://github.com/idan/oauthlib/blob/master/docs/server.rst .. _OAuthProvider source: https://github.com/ib-lundgren/flask-oauthprovider/blob/master/flask_oauthprovider.py .. _Client registration: https://github.com/ib-lundgren/flask-oauthprovider/raw/master/docs/images/client_registration.png .. _Request tokens: https://github.com/ib-lundgren/flask-oauthprovider/raw/master/docs/images/request_token.png .. _Access tokens: https://github.com/ib-lundgren/flask-oauthprovider/raw/master/docs/images/access_token.png .. _Request verification: https://github.com/ib-lundgren/flask-oauthprovider/raw/master/docs/images/request_verification.png

Install

Flask-OAuthProvider will be easily installed using pip when OAuthLib 0.2.0 is available on pypi ::

pip install flask-oauthprovider

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.