Skip to main content

UniAuth

https://travis-ci.org/jthi3rry/uniauth.svg?branch=master https://coveralls.io/repos/jthi3rry/uniauth/badge.png?branch=master

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

  • Based on oauthlib and requests

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

Facebook

Use uniauth.Facebook

GitHub

Use uniauth.GitHub

Google

Use uniauth.Google

LinkedIn

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.2

  • Cast default provider name to unicode

  • Fix resource request extra params not used

v0.0.1

  • Initial

Metadata

Release files for uniauth 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for uniauth 0.0.2
File Size Uploaded Provenance Actions
uniauth-0.0.2.tar.gz 10.1 kB Without provenance Details for uniauth-0.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for uniauth 0.0.2
File Interpreter ABI Platform Actions
uniauth-0.0.2-py2.py3-none-any.whl Python 3, Python 2 none any Details for uniauth-0.0.2-py2.py3-none-any.whl

Total release size: 21.9 kB

Release files / uniauth-0.0.2.tar.gz

Download URL uniauth-0.0.2.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
97b48e089c7f9f16ccac8048ae504e26b9b72fd38890982efcbcbe73eac229ac
BLAKE2b-256 checksum
How to use checksums
496ce9bcd03e29707a119557bccc835db540756c4858fe0ddd7e3272d1dc9992
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / uniauth-0.0.2-py2.py3-none-any.whl

Download URL uniauth-0.0.2-py2.py3-none-any.whl
Size 11.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
03d0e4b4edbcdffda8440f3a0d98b2dac9427ebf6d82d89752a0be3444d3c499
BLAKE2b-256 checksum
How to use checksums
2a69713067ed2aa8bead14f1232945ebec39dd65ce1e6d37fddd30f1c6c19194
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for uniauth 0.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page