/usr/share/pyshared/social_auth/backends/contrib/instagram.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 | from urllib import urlencode
from django.utils import simplejson
from social_auth.backends import BaseOAuth2, OAuthBackend
from social_auth.utils import dsa_urlopen
INSTAGRAM_SERVER = 'instagram.com'
INSTAGRAM_AUTHORIZATION_URL = 'https://instagram.com/oauth/authorize'
INSTAGRAM_ACCESS_TOKEN_URL = 'https://instagram.com/oauth/access_token'
INSTAGRAM_CHECK_AUTH = 'https://api.instagram.com/v1/users/self'
class InstagramBackend(OAuthBackend):
name = 'instagram'
@classmethod
def extra_data(cls, user, uid, response, details=None):
"""Return access_token and extra defined names to store in
extra_data field"""
data = super(InstagramBackend, cls).extra_data(user, uid, response,
details)
try:
data['username'] = response['user']['username']
except KeyError:
pass
return data
def get_user_id(self, details, response):
return response['user']['id']
def get_user_details(self, response):
"""Return user details from Instagram account"""
username = response['user']['username']
fullname = response['user'].get('full_name', '')
email = response['user'].get('email', '')
return {
'username': username,
'first_name': fullname,
'email': email
}
class InstagramAuth(BaseOAuth2):
"""Instagram OAuth mechanism"""
AUTHORIZATION_URL = INSTAGRAM_AUTHORIZATION_URL
ACCESS_TOKEN_URL = INSTAGRAM_ACCESS_TOKEN_URL
AUTH_BACKEND = InstagramBackend
SETTINGS_KEY_NAME = 'INSTAGRAM_CLIENT_ID'
SETTINGS_SECRET_NAME = 'INSTAGRAM_CLIENT_SECRET'
def user_data(self, access_token, *args, **kwargs):
"""Loads user data from service"""
params = {'access_token': access_token}
url = INSTAGRAM_CHECK_AUTH + '?' + urlencode(params)
try:
return simplejson.load(dsa_urlopen(url))
except ValueError:
return None
# Backend definition
BACKENDS = {
'instagram': InstagramAuth,
}
|