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)
- Foursquare
- bitly
- GitHub
- StackExchange
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)