Minimalist and framework independent OAuth(1 & 2) consumers
Project description
UniAuth
Minimalist and framework independent package that provides common OAuth (1 & 2) consumers (or the ability to easily add more).
Unifies OAuth1 and OAuth2 flows into one easy and clear dance
Normalises providers’ profiles data
Normalises OAuth1 & 2 tokens for storage/restoration
Installation
pip install uniauth
Usage
Retrieve a token:
from uniauth import Bitbucket, GitHub # Use an OAuth2 client client = GitHub(client_id="****************", client_secret="****************", scope=None) # Or an OAuth1 client client = Bitbucket(client_id="****************", client_secret="****************") # Provides a unified flow for both OAuth1 & OAuth2 oauth_dance = client.dance(stash, "http://example.org/oauth/callback") # 'stash' allows to complete the oauth dance over multiple requests (by maintaining OAuth1's request token or OAuth2's state) # It can be anything as long as it implements __setattr__(key, value) and pop(key, default) # e.g.: # stash = request.session # Or # stash = {} # Redirect your user to: oauth_dance.get_authorization_url() # Get the access token using the absolute url the povider redirected your user to: normalised_token = oauth_dance.get_access_token(callback_url) # {"token": "**********", "extra": "**********", "expires_at": None, "scope": None} # The token is also stored in the client state client.get_profile()
Restore a token:
# OAuth2 client client = GitHub(client_id="****************", client_secret="****************", scope=None, token=normalised_token) # or OAuth1 client client = Bitbucket(client_id="****************", client_secret="****************", token=normalised_token) client.get_profile()
Request any resource:
# client.request has a similar signature to requests.request but with an optional method (it uses "GET" by default) response = client.request(url_to_resource) # response is an instance of requests.Response response.raise_for_status() data = response.json()
That’s it.
Available Consumers
Bitbucket
Use uniauth.Bitbucket
Use uniauth.Facebook
GitHub
Use uniauth.GitHub
Use uniauth.Google
Use uniauth.LinkedIn
Contribute More
It’s easy to add more consumers:
from uniauth.base import ProfileMixin from uniauth.oauth2 import OAuth2Consumer class MyProviderName(ProfileMixin, OAuth2Consumer): authorization_url = "https://example.org/oauth2/authorization" access_token_url = "https://example.org/oauth2/access_token" profile_url = "https://example.org/user/" def normalize_profile_data(self, data): # transform provider's format into normalised format return {"uid": data.get("id"), "email": data.get("email_address"), "username": data.get("login"), "first_name": data.get("given_name"), "last_name": data.get("family_name"), "gender": data.get("sex"), "birthdate": data.get("dob"), "avatar_url": data.get("picture"), "is_verified": data.get("verified")}
Running Tests
Get a copy of the repository:
git clone git@github.com:OohlaLabs/uniauth.git .
Install tox:
pip install tox
Run the tests:
tox
Contributions
All contributions and comments are welcome.
Change Log
v0.0.1
Initial
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for uniauth-0.0.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4cce6b00ef36bc7213d37b56bf2a7ad6d70bde87237f709ff8b127819bbee982 |
|
MD5 | dfb68fe2c0ef462280d2afd0726d0187 |
|
BLAKE2b-256 | cd979f43e1f06c2630da39b1c77390dda1df44357ca0349875ab581e1fd241bd |