Code Monkey home page Code Monkey logo

flask-oauthprovider's Introduction

Flask-OAuthProvider

July/2013: Good news and Bad news.

Bad: Unfortunately I am unable to dedicate much time to this extension and with the refactoring of OAuth 1 provider in oauthlib 0.5 quite a few changes are required to flask-oauthprovider. Some might break existing implementations. I've set version requirement of oauthlib to < 0.5 to prevent breakage for now.

Good: There is a great new flask extension called flask-oauthlib under active development with support for both OAuth 1 and 2. I strongly encourage every user of flask-oauthprovider to move over to flask-oauthlib. It should be quite painless and result in a cleaner, more Flasky, implementation for all =)


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.

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

MongoDB Example

This repo also includes a fully working, MongoDB / pymongo backed OAuth provider in the /examples folder.

Before running the demo you need to install a few dependencies (virtualenv is highly recommended).:

$ 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 pymongo

After installing you can run the demo application:

(venv)$ python flask-oauthprovider/examples/runserver_mongo.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.

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):
    ...

Install

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

pip install flask-oauthprovider

flask-oauthprovider's People

Contributors

datalogics-kam avatar ib-lundgren avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

flask-oauthprovider's Issues

Dependency on oauthlib >=0.2.0

Is there a way to work around this requisite, or is it possible to get a time esitmate on when oauthlib-0.2.0 will be released?

Thank you!

ImportError: No module named flask.ext.oauthprovider

Hi!

When I try tu run: python flask-oauthprovider/examples/runserver.py

it says:

Traceback (most recent call last):
File "flask-oauthprovider/examples/runserver.py", line 1, in
from demoprovider import app
File "/Users/alasarr/dev/geoscope/api/flask-oauthprovider/examples/demoprovider/init.py", line 2, in
from provider import ExampleProvider
File "/Users/alasarr/dev/geoscope/api/flask-oauthprovider/examples/demoprovider/provider.py", line 2, in
from flask.ext.oauthprovider import OAuthProvider
File "/Users/alasarr/dev/geoscope/api/venv/lib/python2.7/site-packages/flask/exthook.py", line 86, in load_module
raise ImportError('No module named %s' % fullname)
ImportError: No module named flask.ext.oauthprovider

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.