pip install Authomatic
python
from authomatic import Authomatic
from authomatic.providers import oauth2, oauth1
CONFIG = {
'google': {
'class_': oauth2.Google,
'consumer_key': 'YOUR_CONSUMER_KEY',
'consumer_secret': 'YOUR_CONSUMER_SECRET',
'scope': ['email', 'profile'],
},
'facebook': {
'class_': oauth2.Facebook,
'consumer_key': 'YOUR_CONSUMER_KEY',
'consumer_secret': 'YOUR_CONSUMER_SECRET',
'scope': ['email', 'user_about_me'],
},
}
authomatic = Authomatic(CONFIG, 'YOUR_SECRET_KEY', report_errors=True)
result = authomatic.login(oauth2.Facebook, request)
if result:
if result.user:
print("User:", result.user)
access_token = result.user.credentials.token
elif result.error:
print("Error:", result.error)
else:
return result