skip to navigation
skip to content

Not Logged In

basic_oauth 0.1.3

Implements the "Resource Owner Password Credentials Grant" from Oauth v2.

Latest Version: 0.1.5

Basic OAuth v2
==============

What is it?
-----------

The Oauth v2 spec defines several authorization grant. This library implements
the "Resource Owner Password Credentials Grant" as described in
<http://tools.ietf.org/html/draft-ietf-oauth-v2-31#section-4.3>

Requirements:

* [Flask](http://flask.pocoo.org/)
* [Redis](http://redis.io/)

Why using it?
-------------

The goal of this Grant is to replace the classic "HTTP Basic over SSL" widely
used. With Oauth, you exchange your crendentials against a token.

This mechanism has several advantages:

* The client does not pass the full credentials for each request.
* The server does not check the username and password each time, it will
  only check the access token, this will reduce the database lookups.

Basic Oauth uses Redis to store the sessions.

Is it secure?
-------------

__It would be stupid to use this mechanism without SSL__. Even if the token is
passed instead of the credentials, the credentials needs to be passed in clear
text during the Authentication phase. Also, it can be problematic to lose the
token.

To limit the risk of losing the token, every single token generated is signed
using the User-Agent and the client IP address. If an attacker tries to re-use
a stolen token, he will have to connect to the same IP and using the same
User-Agent (browser version, OS, architecture) to get access. A wrong try will
result in destroying the session.

How to use it?
--------------

Install basic_oauth from PYPI:

```
pip install basic_oauth
```

Create a sample WSGI app with [Flask](http://flask.pocoo.org/):

```python
import flask
import basic_oauth

app = flask.Flask(__name__)

oauth = basic_oauth.BasicOauth(app)
oauth.mount_endpoint('login', '/login')
oauth.mount_endpoint('script', '/js/oauth_client.js')
oauth.credentials.append(('johndoe', 'foobar42'))
# You can declare "oauth.authenticate_handler" to plug your own
# database instead of using the in-memory credentials

@app.route('/')
@oauth.require
def hello(user_id):
    return 'Hello World!'

if __name__ == '__main__':
    app.debug = True
    app.run()
```

Checkout the ["example" directory](https://github.com/samalba/basic_oauth/tree/master/example) for a complete server/client example.
 
File Type Py Version Uploaded on Size
basic_oauth-0.1.3.tar.gz (md5) Source 2012-09-17 5KB
  • Downloads (All Versions):
  • 58 downloads in the last day
  • 340 downloads in the last week
  • 1135 downloads in the last month
  • Author: Sam Alba
  • Home Page: http://github.com/samalba/basic_oauth
  • License:
    Copyright (c) 2012 Samuel Alba <sam.alba@gmail.com>
    
    Permission is hereby granted, free of charge, to any person obtaining a copy 
    of this software and associated documentation files (the "Software"), to deal 
    in the Software without restriction, including without limitation the rights 
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
    copies of the Software, and to permit persons to whom the Software is 
    furnished to do so, subject to the following conditions:
    
    The above copyright notice and this permission notice shall be included in all 
    copies or substantial portions of the Software.
    
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
    SOFTWARE.
  • Package Index Owner: shad
  • DOAP record: basic_oauth-0.1.3.xml