/usr/share/pyshared/social_auth/backends/contrib/angel.py is in python-django-social-auth 0.7.23-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | """
settings.py should include the following:
ANGEL_CLIENT_ID = '...'
ANGEL_CLIENT_SECRET = '...'
Optional scope to include 'email' and/or 'messages' separated by space:
ANGEL_AUTH_EXTRA_ARGUMENTS = {'scope': 'email messages'}
More information on scope can be found at https://angel.co/api/oauth/faq
"""
from urllib import urlencode
from django.utils import simplejson
from social_auth.backends import BaseOAuth2, OAuthBackend
from social_auth.utils import dsa_urlopen
ANGEL_SERVER = 'angel.co'
ANGEL_AUTHORIZATION_URL = 'https://angel.co/api/oauth/authorize/'
ANGEL_ACCESS_TOKEN_URL = 'https://angel.co/api/oauth/token/'
ANGEL_CHECK_AUTH = 'https://api.angel.co/1/me/'
class AngelBackend(OAuthBackend):
name = 'angel'
def get_user_id(self, details, response):
return response['id']
def get_user_details(self, response):
"""Return user details from Angel account"""
username = response['angellist_url'].split('/')[-1]
first_name = response['name'].split(' ')[0]
last_name = response['name'].split(' ')[-1]
email = response['email']
return {
'username': username,
'first_name': first_name,
'last_name': last_name,
'email': email,
}
class AngelAuth(BaseOAuth2):
"""Angel OAuth mechanism"""
AUTHORIZATION_URL = ANGEL_AUTHORIZATION_URL
ACCESS_TOKEN_URL = ANGEL_ACCESS_TOKEN_URL
AUTH_BACKEND = AngelBackend
SETTINGS_KEY_NAME = 'ANGEL_CLIENT_ID'
SETTINGS_SECRET_NAME = 'ANGEL_CLIENT_SECRET'
REDIRECT_STATE = False
STATE_PARAMETER = False
def user_data(self, access_token, *args, **kwargs):
"""Loads user data from service"""
params = {'access_token': access_token}
url = ANGEL_CHECK_AUTH + '?' + urlencode(params)
try:
return simplejson.load(dsa_urlopen(url))
except ValueError:
return None
# Backend definition
BACKENDS = {
'angel': AngelAuth,
}
|