12

Code Snippet

from sanction.client import Client
from sanction.adapters.google import Google

client = Client(Google, {
    "google.client_id": "myclientid",
    "google.client_secret": "myclientsecret",
    "google.redirect_uri": "myredirecturi",
    "google.scope": "myscope",
    "google.access_type": "online" # google-specific
})

# get authorization
my_redirect_fn(client.flow.authorization_uri())

# returned to your app (subsequent request)
client.flow.authorization_received(server_response_dict)

# if all goes well in previous call
client.request("/userinfo")

About

Note: Sanction is nearing alpha state, so usage and issue logs are appreciated.

Sanction is a Python implementation of the OAuth 2.0 protocol. It was written to cover issues missed by other implementations:

  • Support for multiple providers (protocol deviations). This didn't seem to be supported by any library.
  • Actually an OAuth2 implementation (python-oauth2 is a 2nd version of python-oauth, not an actual OAuth2 implementation)
  • Support for the entire OAuth2 spec. Most provide support for the authorization request flow (employed by all web server providers) with Bearer token credentials, but lacked support or extensibility for any other flows, credentials or other provider extensions)
  • 100% unit test coverage. Some employed TDD, others didn't.

The library is for anyone wanting to access protected resources via OAuth 2.0.

Currently, there are implementations for:

  • Google
  • Facebook
  • Foursquare
  • Deviant Art
  • Stack Exchange

License

MIT

Platform

Python

Contact

Demian Brecht <demianbrecht [at] gmail.com>

Code

https://github.com/demianbrecht/sanction

Contributions can be made through pull requests.

0

2 Answers 2

2

FWIW, this library has undergone a major overhaul and now lives as a much happier Pythonic module (went from ~450 LOC to 66) and can be found at https://github.com/demianbrecht/sanction.

1

...And now also supports Python 3 (Github version, not uploaded to PyPI yet).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .