Created
January 4, 2017 16:26
-
-
Save paul-english/8dec29a053aba2519d7c40191e487c53 to your computer and use it in GitHub Desktop.
Asana Python Social Auth
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import urllib.error | |
import urllib.parse | |
import urllib.request | |
from social.backends.oauth import BaseOAuth2 | |
class AsanaOAuth2(BaseOAuth2): | |
"""Asana OAuth authentication backend""" | |
name = 'asana' | |
AUTHORIZATION_URL = 'https://app.asana.com/-/oauth_authorize' | |
ACCESS_TOKEN_URL = 'https://app.asana.com/-/oauth_token' | |
ACCESS_TOKEN_METHOD = 'POST' | |
REDIRECT_STATE = False | |
REFRESH_TOKEN_URL = 'https://app.asana.com/-/oauth_token' | |
REFRESH_TOKEN_METHOD = 'POST' | |
EXTRA_DATA = [ | |
('expires_in', 'expires_in',), | |
('token_type', 'token_type',), | |
('refresh_token', 'refresh_token',), | |
('data', 'data',), | |
] | |
# from social.apps.django_app.utils import load_strategy | |
# strategy = load_strategy() | |
# sa = user.social_auth.get(provider='asana') | |
# sa.refresh_token(strategy) | |
# REQUIRES_EMAIL_VALIDATION = True | |
# EXTRA_DATA = [] | |
# RESPONSE_TYPE = '' | |
def get_user_details(self, response): | |
data = response.get('data') | |
return { | |
'email': data.get('email'), | |
'id': data.get('id'), | |
'name': data.get('name'), | |
'photo': data.get('photo'), | |
'workspaces': data.get('workspaces') | |
} | |
def user_data(self, access_token, *args, **kwargs): | |
url = 'https://app.asana.com/api/1.0/users/me' | |
headers = {"Authorization": "Bearer %s" % access_token} | |
req = urllib.request.Request(url, headers=headers) | |
response = urllib.request.urlopen(req) | |
return json.load(response) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment