def get_user_info(self): raw_xml = self.query(self.url) try: user_element = ElementTree.fromstring(raw_xml).find("user") user_info = user_element.attrib user_avatar = user_element.find("img") if user_avatar is not None: user_info.update({"avatar": user_avatar.attrib.get("href")}) return user_info except (ExpatError, KeyError, IndexError): return None class OpenStreetMapOAuthAdapter(OAuthAdapter): provider_id = OpenStreetMapProvider.id request_token_url = "https://www.openstreetmap.org/oauth/request_token" access_token_url = "https://www.openstreetmap.org/oauth/access_token" authorize_url = "https://www.openstreetmap.org/oauth/authorize" def complete_login(self, request, app, token, response): client = OpenStreetMapAPI(request, app.client_id, app.secret, self.request_token_url) extra_data = client.get_user_info() return self.get_provider().sociallogin_from_response( request, extra_data) oauth_login = OAuthLoginView.adapter_view(OpenStreetMapOAuthAdapter) oauth_callback = OAuthCallbackView.adapter_view(OpenStreetMapOAuthAdapter)
access_token_url = 'https://trello.com/1/OAuthGetAccessToken' authorize_url = 'https://trello.com/1/OAuthAuthorizeToken' profile_url = 'https://trello.com/1/members/me' def complete_login(self, request, app, token): consumer = oauth.Consumer(key=app.key, secret=app.secret) access_token = oauth.Token(key=token.token, secret=token.token_secret) client = oauth.Client(consumer, access_token) client.ca_certs = certifi.where() response, data = client.request(self.profile_url) extra_data = json.loads(data) full_name = extra_data.get('fullName', '').split(' ') user = User( username=extra_data.get('username', ''), email=extra_data.get('email', ''), first_name=full_name[0] if full_name else '', last_name=full_name[1] if len(full_name) > 1 else '', ) account = SocialAccount( user=user, uid=extra_data.get('id'), extra_data=extra_data, provider=self.provider_id ) return SocialLogin(account) oauth_login = OAuthLoginView.adapter_view(TrelloOAuthAdapter) oauth_callback = OAuthCallbackView.adapter_view(TrelloOAuthAdapter)
from .provider import DropboxProvider class DropboxAPI(OAuth): """ Verifying dropbox credentials """ url = 'https://api.dropbox.com/1/account/info' def get_user_info(self): user = json.loads(self.query(self.url)) return user class DropboxOAuthAdapter(OAuthAdapter): provider_id = DropboxProvider.id request_token_url = 'https://api.dropbox.com/1/oauth/request_token' access_token_url = 'https://api.dropbox.com/1/oauth/access_token' authorize_url = 'https://www.dropbox.com/1/oauth/authorize' def complete_login(self, request, app, token, response): client = DropboxAPI(request, app.client_id, app.secret, self.request_token_url) extra_data = client.get_user_info() return self.get_provider().sociallogin_from_response(request, extra_data) oauth_login = OAuthLoginView.adapter_view(DropboxOAuthAdapter) oauth_callback = OAuthCallbackView.adapter_view(DropboxOAuthAdapter)
elif app_settings.PROVIDERS['kony'].get('environment', 'prod') == 'prod': url = 'https://api.kony.com/api/v1_0/whoami' def get_user_info(self): raw_json = self.query(self.url, method="POST") user_info = json.loads(raw_json) return user_info class KonyOAuthAdapter(OAuthAdapter): provider_id = KonyProvider.id if app_settings.PROVIDERS['kony'].get('environment', 'dev') == 'dev': request_token_url = 'https://manage.dev-kony.com/oauth/request_token' access_token_url = 'https://manage.dev-kony.com/oauth/access_token' authorize_url = 'https://manage.dev-kony.com/oauth/authorize' elif app_settings.PROVIDERS['kony'].get('environment', 'dev') == 'prod': request_token_url = 'https://manage.kony.com/oauth/request_token' access_token_url = 'https://manage.kony.com/oauth/access_token' authorize_url = 'https://manage.kony.com/oauth/authorize' def complete_login(self, request, app, token, response): client = KonyAPI(request, app.client_id, app.secret, self.request_token_url) extra_data = client.get_user_info() return self.get_provider().sociallogin_from_response(request, extra_data) oauth_login = OAuthLoginView.adapter_view(KonyOAuthAdapter) oauth_callback = OAuthCallbackView.adapter_view(KonyOAuthAdapter)
API_BASE = 'https://api.500px.com/v1' class FiveHundredPxAPI(OAuth): """ Verifying 500px credentials """ url = API_BASE + '/users' def get_user_info(self): return json.loads(self.query(self.url))['user'] class FiveHundredPxOAuthAdapter(OAuthAdapter): provider_id = FiveHundredPxProvider.id request_token_url = API_BASE + '/oauth/request_token' access_token_url = API_BASE + '/oauth/access_token' authorize_url = API_BASE + '/oauth/authorize' def complete_login(self, request, app, token, response): client = FiveHundredPxAPI(request, app.client_id, app.secret, self.request_token_url) extra_data = client.get_user_info() return self.get_provider().sociallogin_from_response(request, extra_data) oauth_login = OAuthLoginView.adapter_view(FiveHundredPxOAuthAdapter) oauth_callback = OAuthCallbackView.adapter_view(FiveHundredPxOAuthAdapter)
def get_user_info(self): default_params = {'nojsoncallback': '1', 'format': 'json'} p = dict({'method': 'flickr.test.login'}, **default_params) u = json.loads(self.query(self.api_url + '?' + urlencode(p))) p = dict( { 'method': 'flickr.people.getInfo', 'user_id': u['user']['id'] }, **default_params) user = json.loads(self.query(self.api_url + '?' + urlencode(p))) return user class FlickrOAuthAdapter(OAuthAdapter): provider_id = FlickrProvider.id request_token_url = 'http://www.flickr.com/services/oauth/request_token' access_token_url = 'http://www.flickr.com/services/oauth/access_token' authorize_url = 'http://www.flickr.com/services/oauth/authorize' def complete_login(self, request, app, token, response): client = FlickrAPI(request, app.client_id, app.secret, self.request_token_url) extra_data = client.get_user_info() return self.get_provider().sociallogin_from_response( request, extra_data) oauth_login = OAuthLoginView.adapter_view(FlickrOAuthAdapter) oauth_callback = OAuthCallbackView.adapter_view(FlickrOAuthAdapter)
OAuthLoginView, ) from .provider import TumblrProvider class TumblrAPI(OAuth): url = 'http://api.tumblr.com/v2/user/info' def get_user_info(self): data = json.loads(self.query(self.url)) return data['response']['user'] class TumblrOAuthAdapter(OAuthAdapter): provider_id = TumblrProvider.id request_token_url = 'https://www.tumblr.com/oauth/request_token' access_token_url = 'https://www.tumblr.com/oauth/access_token' authorize_url = 'https://www.tumblr.com/oauth/authorize' def complete_login(self, request, app, token, response): client = TumblrAPI(request, app.client_id, app.secret, self.request_token_url) extra_data = client.get_user_info() return self.get_provider().sociallogin_from_response(request, extra_data) oauth_login = OAuthLoginView.adapter_view(TumblrOAuthAdapter) oauth_callback = OAuthCallbackView.adapter_view(TumblrOAuthAdapter)
def get_user_info(self): # TODO: Actually turn these into EmailAddress emails = json.loads(self.query(self.emails_url)) for address in reversed(emails): if address["active"]: email = address["email"] if address["primary"]: break data = json.loads(self.query(self.users_url + email)) user = data["user"] return user class BitbucketOAuthAdapter(OAuthAdapter): provider_id = BitbucketProvider.id request_token_url = "https://bitbucket.org/api/1.0/oauth/request_token" access_token_url = "https://bitbucket.org/api/1.0/oauth/access_token" authorize_url = "https://bitbucket.org/api/1.0/oauth/authenticate" def complete_login(self, request, app, token, response): client = BitbucketAPI(request, app.client_id, app.secret, self.request_token_url) extra_data = client.get_user_info() return self.get_provider().sociallogin_from_response( request, extra_data) oauth_login = OAuthLoginView.adapter_view(BitbucketOAuthAdapter) oauth_callback = OAuthCallbackView.adapter_view(BitbucketOAuthAdapter)
email = json.loads(response1)['email'] obj = json.loads(response2) name = '%s %s' % (obj['name'], obj['surname']) user = { 'uu': email, 'firstname': obj['name'], 'surname': obj['surname'], 'name': name } return user class UaOAuthAdapter(OAuthAdapter): provider_id = UaProvider.id request_token_url = 'http://identity.ua.pt/oauth/request_token' access_token_url = 'http://identity.ua.pt/oauth/access_token' authorize_url = 'http://identity.ua.pt/oauth/authorize' def complete_login(self, request, app, token): client = UaAPI(request, app.client_id, app.secret, self.request_token_url) extra_data = client.get_user_info() return self.get_provider().sociallogin_from_response( request, extra_data) oauth_login = OAuthLoginView.adapter_view(UaOAuthAdapter) oauth_callback = OAuthCallbackView.adapter_view(UaOAuthAdapter)
OAuthCallbackView, OAuthLoginView, ) from .provider import EvernoteProvider class EvernoteOAuthAdapter(OAuthAdapter): provider_id = EvernoteProvider.id settings = app_settings.PROVIDERS.get(provider_id, {}) request_token_url = 'https://%s/oauth' % (settings.get( 'EVERNOTE_HOSTNAME', 'sandbox.evernote.com')) access_token_url = 'https://%s/oauth' % (settings.get( 'EVERNOTE_HOSTNAME', 'sandbox.evernote.com')) authorize_url = 'https://%s/OAuth.action' % (settings.get( 'EVERNOTE_HOSTNAME', 'sandbox.evernote.com')) def complete_login(self, request, app, token, response): token.expires_at = datetime.fromtimestamp( int(response['edam_expires']) / 1000.0) extra_data = response return self.get_provider().sociallogin_from_response(request, extra_data) oauth_login = OAuthLoginView.adapter_view(EvernoteOAuthAdapter) oauth_callback = OAuthCallbackView.adapter_view(EvernoteOAuthAdapter)
class TwitterOAuthAdapter(OAuthAdapter): provider_id = TwitterProvider.id request_token_url = 'https://api.twitter.com/oauth/request_token' access_token_url = 'https://api.twitter.com/oauth/access_token' # Issue #42 -- this one authenticates over and over again... #authorize_url = 'https://api.twitter.com/oauth/authorize' authorize_url = 'https://api.twitter.com/oauth/authenticate' def complete_login(self, request, app, token): client = TwitterAPI(request, app.client_id, app.secret, self.request_token_url) extra_data = client.get_user_info() uid = extra_data['id'] user = User(username=extra_data['screen_name']) account = SocialAccount(user=user, uid=uid, provider=TwitterProvider.id, extra_data=extra_data) return SocialLogin(account) class TwitterFullAuthorizationAdapter(TwitterOAuthAdapter): authorize_url = 'https://api.twitter.com/oauth/authorize' oauth_authorize = OAuthLoginView.adapter_view(TwitterFullAuthorizationAdapter) oauth_login = OAuthLoginView.adapter_view(TwitterOAuthAdapter) oauth_callback = OAuthCallbackView.adapter_view(TwitterOAuthAdapter)
#extra_data = resp.json() #if app_settings.QUERY_EMAIL and not extra_data.get('email'): # extra_data['email'] = self.get_email(token) client = GoodreadsAPI(request, app.client_id, app.secret, self.request_token_url) extra_data = client.get_user_info() return self.get_provider().sociallogin_from_response( request, extra_data ) def get_email(self, token): email = None params = {'access_token': token.token} resp = requests.get(self.emails_url, params=params) emails = resp.json() if resp.status_code == 200 and emails: email = emails[0] primary_emails = [ e for e in emails if not isinstance(e, dict) or e.get('primary') ] if primary_emails: email = primary_emails[0] if isinstance(email, dict): email = email.get('email', '') return email oauth2_login = OAuthLoginView.adapter_view(GoodreadsOAuthAdapter) oauth2_callback = OAuthCallbackView.adapter_view(GoodreadsOAuthAdapter)
) from .provider import VimeoProvider class VimeoAPI(OAuth): url = 'http://vimeo.com/api/rest/v2?method=vimeo.people.getInfo' def get_user_info(self): url = self.url data = json.loads(self.query(url, params=dict(format='json'))) return data['person'] class VimeoOAuthAdapter(OAuthAdapter): provider_id = VimeoProvider.id request_token_url = 'https://vimeo.com/oauth/request_token' access_token_url = 'https://vimeo.com/oauth/access_token' authorize_url = 'https://vimeo.com/oauth/authorize' def complete_login(self, request, app, token, response): client = VimeoAPI(request, app.client_id, app.secret, self.request_token_url) extra_data = client.get_user_info() return self.get_provider().sociallogin_from_response(request, extra_data) oauth_login = OAuthLoginView.adapter_view(VimeoOAuthAdapter) oauth_callback = OAuthCallbackView.adapter_view(VimeoOAuthAdapter)
authorize_url = 'https://websignon.warwick.ac.uk/oauth/authenticate' def complete_login(self, request, app, token): client = WarwickAPI(request, app.client_id, app.secret, self.request_token_url) extra_data = client.get_user_info() uid = extra_data['user'] user = User(username=extra_data['user'], email=extra_data.get('email', ''), first_name=extra_data.get('firstname', ''), last_name=extra_data.get('lastname', '')) email_addresses = [] if user.email: email_addresses.append(EmailAddress(email=user.email, verified=True, primary=True)) account = SocialAccount(user=user, uid=uid, provider=WarwickProvider.id, extra_data=extra_data) return SocialLogin(account, email_addresses=email_addresses) OAuthLoginView._get_client = _get_client OAuthCallbackView._get_client = _get_client oauth_login = OAuthLoginView.adapter_view(WarwickOAuthAdapter) oauth_callback = OAuthCallbackView.adapter_view(WarwickOAuthAdapter)
OAuthAdapter, OAuthCallbackView, OAuthLoginView, ) from .provider import XingProvider class XingAPI(OAuth): url = "https://api.xing.com/v1/users/me.json" def get_user_info(self): user = json.loads(self.query(self.url)) return user class XingOAuthAdapter(OAuthAdapter): provider_id = XingProvider.id request_token_url = "https://api.xing.com/v1/request_token" access_token_url = "https://api.xing.com/v1/access_token" authorize_url = "https://www.xing.com/v1/authorize" def complete_login(self, request, app, token, response): client = XingAPI(request, app.client_id, app.secret, self.request_token_url) extra_data = client.get_user_info()["users"][0] return self.get_provider().sociallogin_from_response(request, extra_data) oauth_login = OAuthLoginView.adapter_view(XingOAuthAdapter) oauth_callback = OAuthCallbackView.adapter_view(XingOAuthAdapter)
default_params = {'nojsoncallback': '1', 'format': 'json'} p = dict({'method': 'flickr.test.login'}, **default_params) u = json.loads(self.query(self.api_url + '?' + urlencode(p))) p = dict({'method': 'flickr.people.getInfo', 'user_id': u['user']['id']}, **default_params) user = json.loads( self.query(self.api_url + '?' + urlencode(p))) return user class FlickrOAuthAdapter(OAuthAdapter): provider_id = FlickrProvider.id request_token_url = 'http://www.flickr.com/services/oauth/request_token' access_token_url = 'http://www.flickr.com/services/oauth/access_token' authorize_url = 'http://www.flickr.com/services/oauth/authorize' def complete_login(self, request, app, token, response): client = FlickrAPI(request, app.client_id, app.secret, self.request_token_url) extra_data = client.get_user_info() return self.get_provider().sociallogin_from_response(request, extra_data) oauth_login = OAuthLoginView.adapter_view(FlickrOAuthAdapter) oauth_callback = OAuthCallbackView.adapter_view(FlickrOAuthAdapter)
) import json from .provider import TumblrProvider class TumblrAPI(OAuth): url = 'http://api.tumblr.com/v2/user/info' def get_user_info(self): data = json.loads(self.query(self.url)) return data['response']['user'] class TumblrOAuthAdapter(OAuthAdapter): provider_id = TumblrProvider.id request_token_url = 'https://www.tumblr.com/oauth/request_token' access_token_url = 'https://www.tumblr.com/oauth/access_token' authorize_url = 'https://www.tumblr.com/oauth/authorize' def complete_login(self, request, app, token, response): client = TumblrAPI(request, app.client_id, app.secret, self.request_token_url) extra_data = client.get_user_info() return self.get_provider().sociallogin_from_response(request, extra_data) oauth_login = OAuthLoginView.adapter_view(TumblrOAuthAdapter) oauth_callback = OAuthCallbackView.adapter_view(TumblrOAuthAdapter)
user = json.loads(self.query(self.url)) return user class TwitterOAuthAdapter(OAuthAdapter): provider_id = TwitterProvider.id request_token_url = 'https://api.twitter.com/oauth/request_token' access_token_url = 'https://api.twitter.com/oauth/access_token' # Issue #42 -- this one authenticates over and over again... # authorize_url = 'https://api.twitter.com/oauth/authorize' authorize_url = 'https://api.twitter.com/oauth/authenticate' def complete_login(self, request, app, token): client = TwitterAPI(request, app.client_id, app.secret, self.request_token_url) extra_data = client.get_user_info() uid = extra_data['id'] account = SocialAccount(uid=uid, provider=TwitterProvider.id, extra_data=extra_data) account.user = get_adapter() \ .populate_new_user(request, account, username=extra_data.get('screen_name'), name=extra_data.get('name')) return SocialLogin(account) oauth_login = OAuthLoginView.adapter_view(TwitterOAuthAdapter) oauth_callback = OAuthCallbackView.adapter_view(TwitterOAuthAdapter)
def get_user_info(self): user = json.loads(self.query(self.url)) #user_avatar = json.loads(self.query(self.url_avatar)) user_shops = json.loads(self.query(self.url_shops)) user_profile = json.loads(self.query(self.url_profile)) data = {"user": user["results"][0], "profile": user_profile["results"][0], "shops": user_shops["results"]} return data class EtsyOAuthAdapter(OAuthAdapter): provider_id = EtsyProvider.id request_token_url = 'https://openapi.etsy.com/v2/oauth/request_token' access_token_url = 'https://openapi.etsy.com/v2/oauth/access_token' # Issue #42 -- this one authenticates over and over again... # authorize_url = 'https://api.twitter.com/oauth/authorize' authorize_url = 'https://www.etsy.com/oauth/signin' def complete_login(self, request, app, token): client = EtsyAPI(request, app.client_id, app.secret, self.request_token_url) extra_data = client.get_user_info() return self.get_provider().sociallogin_from_response(request, extra_data) oauth_login = OAuthLoginView.adapter_view(EtsyOAuthAdapter) oauth_callback = OAuthCallbackView.adapter_view(EtsyOAuthAdapter)
from .provider import TrelloProvider class TrelloOAuthAdapter(OAuthAdapter): provider_id = TrelloProvider.id request_token_url = 'https://trello.com/1/OAuthGetRequestToken' authorize_url = 'https://trello.com/1/OAuthAuthorizeToken' access_token_url = 'https://trello.com/1/OAuthGetAccessToken' def complete_login(self, request, app, token, response): # we need to get the member id and the other information # check: https://developers.trello.com/advanced-reference/token # https://api.trello.com/1/tokens/91a6408305c1e5ec1b0b306688bc2e2f8fe67abf6a2ecec38c17e5b894fcf866?key=[application_key]&token=[optional_auth_token] info_url = '{base}{token}?{query}'.format( base='https://api.trello.com/1/tokens/', token=urlquote(token.token), query=urlencode({ 'key': app.key, 'token': response.get('oauth_token')})) resp = requests.get(info_url) resp.raise_for_status() extra_data = resp.json() result = self.get_provider().sociallogin_from_response(request, extra_data) return result oauth_login = OAuthLoginView.adapter_view(TrelloOAuthAdapter) oauth_callback = OAuthCallbackView.adapter_view(TrelloOAuthAdapter)
from allauth.socialaccount.providers.oauth.views import (OAuthAdapter, OAuthLoginView, OAuthCallbackView) from .provider import XingProvider class XingAPI(OAuth): url = 'https://api.xing.com/v1/users/me.json' def get_user_info(self): user = json.loads(self.query(self.url)) return user class XingOAuthAdapter(OAuthAdapter): provider_id = XingProvider.id request_token_url = 'https://api.xing.com/v1/request_token' access_token_url = 'https://api.xing.com/v1/access_token' authorize_url = 'https://www.xing.com/v1/authorize' def complete_login(self, request, app, token, response): client = XingAPI(request, app.client_id, app.secret, self.request_token_url) extra_data = client.get_user_info()['users'][0] return self.get_provider().sociallogin_from_response(request, extra_data) oauth_login = OAuthLoginView.adapter_view(XingOAuthAdapter) oauth_callback = OAuthCallbackView.adapter_view(XingOAuthAdapter)
OAuthLoginView, OAuthCallbackView) from .provider import VimeoProvider class VimeoAPI(OAuth): url = 'http://vimeo.com/api/rest/v2?method=vimeo.people.getInfo' def get_user_info(self): url = self.url data = json.loads(self.query(url, params=dict(format='json'))) return data['person'] class VimeoOAuthAdapter(OAuthAdapter): provider_id = VimeoProvider.id request_token_url = 'https://vimeo.com/oauth/request_token' access_token_url = 'https://vimeo.com/oauth/access_token' authorize_url = 'https://vimeo.com/oauth/authorize' def complete_login(self, request, app, token): client = VimeoAPI(request, app.client_id, app.secret, self.request_token_url) extra_data = client.get_user_info() return self.get_provider().sociallogin_from_response(request, extra_data) oauth_login = OAuthLoginView.adapter_view(VimeoOAuthAdapter) oauth_callback = OAuthCallbackView.adapter_view(VimeoOAuthAdapter)
from allauth.socialaccount.providers.oauth.views import ( OAuthAdapter, OAuthCallbackView, OAuthLoginView, ) from datetime import datetime from .provider import EvernoteProvider class EvernoteOAuthAdapter(OAuthAdapter): provider_id = EvernoteProvider.id settings = app_settings.PROVIDERS.get(provider_id, {}) request_token_url = 'https://%s/oauth' % (settings.get( 'EVERNOTE_HOSTNAME', 'sandbox.evernote.com')) access_token_url = 'https://%s/oauth' % (settings.get( 'EVERNOTE_HOSTNAME', 'sandbox.evernote.com')) authorize_url = 'https://%s/OAuth.action' % (settings.get( 'EVERNOTE_HOSTNAME', 'sandbox.evernote.com')) def complete_login(self, request, app, token, response): token.expires_at = datetime.fromtimestamp( int(response['edam_expires']) / 1000.0) extra_data = response return self.get_provider().sociallogin_from_response( request, extra_data) oauth_login = OAuthLoginView.adapter_view(EvernoteOAuthAdapter) oauth_callback = OAuthCallbackView.adapter_view(EvernoteOAuthAdapter)
def get_user_info(self): # TODO: Actually turn these into EmailAddress emails = json.loads(self.query(self.emails_url)) for address in reversed(emails): if address['active']: email = address['email'] if address['primary']: break data = json.loads(self.query(self.users_url + email)) user = data['user'] return user class BitbucketOAuthAdapter(OAuthAdapter): provider_id = BitbucketProvider.id request_token_url = 'https://bitbucket.org/api/1.0/oauth/request_token' access_token_url = 'https://bitbucket.org/api/1.0/oauth/access_token' authorize_url = 'https://bitbucket.org/api/1.0/oauth/authenticate' def complete_login(self, request, app, token, response): client = BitbucketAPI(request, app.client_id, app.secret, self.request_token_url) extra_data = client.get_user_info() return self.get_provider().sociallogin_from_response(request, extra_data) oauth_login = OAuthLoginView.adapter_view(BitbucketOAuthAdapter) oauth_callback = OAuthCallbackView.adapter_view(BitbucketOAuthAdapter)
from .provider import DropboxProvider class DropboxAPI(OAuth): """ Verifying twitter credentials """ url = 'https://api.dropbox.com/1/account/info' def get_user_info(self): user = json.loads(self.query(self.url)) return user class DropboxOAuthAdapter(OAuthAdapter): provider_id = DropboxProvider.id request_token_url = 'https://api.dropbox.com/1/oauth/request_token' access_token_url = 'https://api.dropbox.com/1/oauth/access_token' authorize_url = 'https://www.dropbox.com/1/oauth/authorize' def complete_login(self, request, app, token, response): client = DropboxAPI(request, app.client_id, app.secret, self.request_token_url) extra_data = client.get_user_info() return self.get_provider().sociallogin_from_response( request, extra_data) oauth_login = OAuthLoginView.adapter_view(DropboxOAuthAdapter) oauth_callback = OAuthCallbackView.adapter_view(DropboxOAuthAdapter)
out[node.tag] = [out[node.tag]] out[node.tag].append(self.to_dict(node)) else: out[node.tag] = self.to_dict(node) return out class LinkedInOAuthAdapter(OAuthAdapter): provider_id = LinkedInProvider.id request_token_url = 'https://api.linkedin.com/uas/oauth/requestToken' access_token_url = 'https://api.linkedin.com/uas/oauth/accessToken' authorize_url = 'https://www.linkedin.com/uas/oauth/authenticate' def complete_login(self, request, app, token): client = LinkedInAPI(request, app.client_id, app.secret, self.request_token_url) extra_data = client.get_user_info() uid = extra_data['id'] user = get_adapter() \ .populate_new_user(email=extra_data.get('email-address'), first_name=extra_data.get('first-name'), last_name=extra_data.get('last-name')) account = SocialAccount(user=user, provider=self.provider_id, extra_data=extra_data, uid=uid) return SocialLogin(account) oauth_login = OAuthLoginView.adapter_view(LinkedInOAuthAdapter) oauth_callback = OAuthCallbackView.adapter_view(LinkedInOAuthAdapter)
if not children: return xml.text else: out = {} for node in list(xml): if node.tag in out: if not isinstance(out[node.tag], list): out[node.tag] = [out[node.tag]] out[node.tag].append(self.to_dict(node)) else: out[node.tag] = self.to_dict(node) return out class LinkedInOAuthAdapter(OAuthAdapter): provider_id = LinkedInProvider.id request_token_url = 'https://api.linkedin.com/uas/oauth/requestToken' access_token_url = 'https://api.linkedin.com/uas/oauth/accessToken' authorize_url = 'https://www.linkedin.com/uas/oauth/authenticate' def complete_login(self, request, app, token, response): client = LinkedInAPI(request, app.client_id, app.secret, self.request_token_url) extra_data = client.get_user_info() return self.get_provider().sociallogin_from_response( request, extra_data) oauth_login = OAuthLoginView.adapter_view(LinkedInOAuthAdapter) oauth_callback = OAuthCallbackView.adapter_view(LinkedInOAuthAdapter)
url = 'https://twitter.com/account/verify_credentials.json' def get_user_info(self): user = simplejson.loads(self.query(self.url)) return user class TwitterOAuthAdapter(OAuthAdapter): provider_id = TwitterProvider.id request_token_url = 'https://api.twitter.com/oauth/request_token' access_token_url = 'https://api.twitter.com/oauth/access_token' # Issue #42 -- this one authenticates over and over again... # authorize_url = 'https://api.twitter.com/oauth/authorize' authorize_url = 'https://api.twitter.com/oauth/authenticate' def get_user_info(self, request, app): client = TwitterAPI(request, app.key, app.secret, self.request_token_url) user_info = client.get_user_info() uid = user_info['id'] extra_data = { 'profile_image_url': user_info['profile_image_url'], 'screen_name': user_info['screen_name'] } data = dict(twitter_user_info=user_info, username=user_info['screen_name']) return uid, data, extra_data oauth_login = OAuthLoginView.adapter_view(TwitterOAuthAdapter) oauth_callback = OAuthCallbackView.adapter_view(TwitterOAuthAdapter) oauth_complete = OAuthCompleteView.adapter_view(TwitterOAuthAdapter)
class HatenaAPI(OAuth): """ Verifying hatena credentials """ url = 'http://n.hatena.com/applications/my.json' def get_user_info(self): user = json.loads(self.query(self.url)) return user class HatenaOAuthAdapter(OAuthAdapter): provider_id = HatenaProvider.id request_token_url = 'https://www.hatena.com/oauth/initiate' access_token_url = 'https://www.hatena.com/oauth/token' authorize_url = 'https://www.hatena.ne.jp/oauth/authorize' def complete_login(self, request, app, token, response): client = HatenaAPI(request, app.client_id, app.secret, self.request_token_url) # access_token for example: # {'oauth_token': 'hoge', 'oauth_token_secret': 'fuga', 'url_name': 'h3poteto', 'display_name': '平仮名3文字ぽてと'} extra_data = client.get_user_info() return self.get_provider().sociallogin_from_response( request, extra_data) oauth_login = OAuthLoginView.adapter_view(HatenaOAuthAdapter) oauth_callback = OAuthCallbackView.adapter_view(HatenaOAuthAdapter)