9

Overview

sanction is a lightweight, dead simple (67 LOC!) client implementation of the OAuth2 protocol. The major goals of the library are:

  • Support multiple providers
    • Most providers have varying levels of diversion from the official spec. The goal with this library is to either handle these diversions natively, or expose a method to allow client code to deal with it efficiently and effectively.
  • Support all server-side OAuth2 flows
    • Three of the four OAuth2 flows should be supported by this library. Currently, only authorization code and client credential flows have been tested due to lack of other (known) implementations.

Example

c = Client(token_endpoint="https://accounts.google.com/o/oauth2/token",
    resource_endpoint="https://www.googleapis.com/oauth2/v1",
    redirect_uri="http://localhost:8080/login/google",
    client_id=config["google.client_id"],
    client_secret=config["google.client_secret"])

# redirect user to authorization page
my_redirect(client.flow.authorization_uri(state=my_state))

# get access token and make a resource request
c.request_token(response_dict)
c.request("/userinfo")

Supported Providers

The following OAuth2 providers have been (lightly) tested:

  • Facebook (include the test API)
  • Google
  • Foursquare
  • bitly
  • GitHub
  • StackExchange
  • Instagram

There is sample code for each in the example directory.

I decided to re-post this package as not only did the github repo URI change, but it underwent a ridiculously large refactor, going from roughly 470 LOC to 67 (looking nothing like the original)

https://github.com/demianbrecht/sanction

3
  • 1
    No link to the project :) ? Commented Jul 8, 2012 at 6:13
  • @systempuntoout: Eesh. Feeling a little sheepish now.. Added :) Commented Jul 9, 2012 at 2:19
  • 1
    This is promising: can it replace all that facepy, flickrapi or oauth2client altogether? (y)
    – swdev
    Commented Sep 1, 2015 at 10:10

0

You must log in to answer this question.

Browse other questions tagged .