This module provides a simple WSGI middleware that requires the user to authenticate via the specific OAuth 2.0 service e.g. Facebook, Google.
It requires Python 2.6 or higher. (Not tested on Python 3 or higher.) It has no dependencies for non standard libraries, but if there is an installed simplejson library, it will be used instead of the standard json package.
You can install the package via downloading from PyPI:
$ pip install wsgi-oauth2
If you want to use the bleeding edge, install it from the Git repository:
$ pip install git+git://github.com/StyleShare/wsgi-oauth2.git
There are some predefined services.
(Service) The predefined service for Google.
from myapp import app
from wsgioauth2 import github
client = github.make_client(client_id='...', client_secret='...')
app = client.wsgi_middleware(app, secret='hmac*secret')
OAuth 2.0 service provider e.g. Facebook, Google. It takes endpoint urls for authorization and access token gathering APIs.
| Parameters: |
|
|---|
(basestring) The API URL for getting access token.
(basestring) The API URL for authorization.
Load a username from the service suitable for the REMOTE_USER variable. A valid AccessToken is provided to allow access to authenticated resources provided by the service. If the service supports usernames this method must set the ‘username’ parameter to access_token.
| Parameters: | access_token – a valid AccessToken |
|---|
Makes a Client for the service.
| Parameters: |
|
|---|---|
| Returns: | a client for the service |
| Return type: |
Client for Service.
| Parameters: |
|
|---|
(basestring) The client id.
(basestring) The client secret key.
Load a username from the configured service suitable for the REMOTE_USER variable. A valid AccessToken is provided to allow access to authenticated resources provided by the service. For Github the ‘login’ variable is used.
| Parameters: | access_token – a valid AccessToken |
|---|
Makes an authorize URL.
| Parameters: |
|
|---|---|
| Returns: | generated authorize url |
| Return type: | basestring |
Requests an access token.
| Parameters: |
|
|---|---|
| Returns: | access token and additional data |
| Return type: |
Wraps a WSGI application.
Dictionary that contains access token. It always has 'access_token' key.
(basestring) Access token.
Requests url as GET.
| Parameters: | headers (collections.Mapping) – additional headers |
|---|
Requests url as POST.
| Parameters: |
|
|---|
WSGI middleware application.
| Parameters: |
|
|---|
(callable object) The wrapped WSGI application.
(basestring) The cookie name to be used for maintaining the user session.
(basestring) The path prefix for callback URL. It always starts and ends with '/'.
(basestring) The secret key for generating HMAC signature.
The source code is available under MIT license. Check out from the GitHub:
$ git clone git://github.com/StyleShare/wsgi-oauth2.git
We welcome pull requests as well!
If you found bugs or want to propose some improvement ideas, use the issue tracker.
The package is written by Hong Minhee for StyleShare.
Released on March 22, 2013.
Released on May 2, 2012.
Released on November 4, 2011. First version.