Simple Python oAuth Login
Project description
python-socialite
Simple and convenient oAuth Login user provider for Facebook, Twitter, LinkedIn, Google, GitHub, GitLab and Bitbucket. Inspired by [Laravel Socialite](https://laravel.com/docs/master/socialite)Features
- Supports multiple common providers
- Supports any oAuth 2 compliant providers
- Straighforward unopinionated authentication
- Can be implemented in any python framework
Usage
Generate redirect uri
from python_socialite import AuthProvider
config = {
"google": {
"client_id": "",
"client_secret": "",
"redirect_uri": ""
}
}
provider = AuthProvider("google", config)
redirect_url = provider.get_auth_url()
# redirect user to the redirect_url using your frameworks supported redirect
Retrieving Access Token and User
code = "" # read code from GET variables
provider = AuthProvider("google", config)
try:
token = provider.get_token(code)
user = provider.get_user(token["access_token"])
except:
pass
Hook the returned user profile to your apps authentication.
Token Template
NB: Token attributes might vary between providers. Here's a sample returned by Google
{
"access_token":"ya29.***",
"expires_in":3599,
"scope":"https://www.googleapis.com/auth/userinfo.profile openid",
"token_type":"Bearer",
"id_token":"***jwt***"
}
User Template
user = {
"id": "",
"name": "",
"email": "",
"avatar": "",
"raw": "",
"provider": ""
}
The raw
attribute contains all user data as returned by the oAuth provider. Fields in this attribute can be different across different oAuth providers
Requesting Scopes
By default the following scopes are requested
openid, email, profile
You can override requested scopes by adding them to the provider config or using set_scopes
method
provider = OAuthProvider("google", config)
auth_url = provider.set_scopes(["openid", "email", "profile"]).get_auth_url()
NB: If no scopes are set in the config or in code the default scopes will be used
Config Options
The config must be a dict containing keys of any of the supported providers
# each provider key must have client_id, client_secret and redirect_url
config = {
"google": {
"client_id": "",
"client_secret": "",
"redirect_url": "",
"scopes": [] # optional
},
"facebook": {},
"twitter": {},
"linkedin": {},
"github": {},
"gitlab": {},
"bitbucket": {}
}
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
python_socialite-0.1.0.tar.gz
(7.0 kB
view hashes)
Built Distribution
Close
Hashes for python_socialite-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a3193b8b9cc7d84213b2047eb85fe72a5d24895e83a8381cc1f3add1d6e524c |
|
MD5 | 5f6529e732fb44977a721608a2637970 |
|
BLAKE2b-256 | 6ce70ef3987dd237eeb7f5e837f2f5534c4fc28537c373914c9cbf34badca2e0 |