def extract_uid(self, data): if 'id' not in data: raise ProviderException( 'LinkedIn encountered an internal error while logging in. \ Please try again.' ) return str(data['id'])
def save(self, request): # SOCIALACCOUNT_FORMS.signup is unique, but providers are multiple. # Find the correct adapter to save the new User. if self.sociallogin.account.provider == DootixProvider.id: adapter = DootixSocialAccountAdapter(request) elif self.sociallogin.account.provider == GeomapfishProvider.id: adapter = GeomapfishSocialAccountAdapter(request) else: raise ProviderException(_("Unknown social account provider")) return adapter.save_user(request, self.sociallogin, form=self)
def extract_common_fields(self, data): if not data.get('verified', False): raise ProviderException( "Login failed. Discord account is unverified.") name = '{0}#{1}'.format(data.get('username'), data.get('discriminator')) return dict(email=data.get('email'), username=data.get('id'), first_name=name, name=name)
def complete_login(self, request, app, token, **kwargs): headers = {'Authorization': 'Bearer %s' % token.token} resp = requests.get(self.get_profile_url(request), headers=headers) extra_data = resp.json() """ Douban may return data like this: { 'code': 128, 'request': 'GET /v2/user/~me', 'msg': 'user_is_locked:53358092' } """ if 'id' not in extra_data: msg = extra_data.get('msg', _('Invalid profile data')) raise ProviderException(msg) return self.sociallogin_from_response(request, extra_data)
def complete_login(self, request, app, token, **kwargs): ''' Arguments: request - The get request to the callback URL /accounts/dataporten/login/callback. app - The corresponding SocialApp model instance token - A token object with access token given in token.token Returns: Should return a dict with user information intended for parsing by the methods of the DataportenProvider view, i.e. extract_uid(), extract_extra_data(), and extract_common_fields() ''' # The athentication header headers = {'Authorization': 'Bearer ' + token.token} # Userinfo endpoint, for documentation see: # https://docs.dataporten.no/docs/oauth-authentication/ userinfo_response = requests.get( self.get_profile_url(request), headers=headers, ) # Raise exception for 4xx and 5xx response codes userinfo_response.raise_for_status() # The endpoint returns json-data and it needs to be decoded extra_data = userinfo_response.json()['user'] # Finally test that the audience property matches the client id # for validification reasons, as instructed by the Dataporten docs # if the userinfo-response is used for authentication if userinfo_response.json()['audience'] != app.client_id: raise ProviderException( 'Dataporten returned a user with an audience field \ which does not correspond to the client id of the \ application.' ) return self.sociallogin_from_response( request, extra_data, )
def extract_uid(self, data): ret = data.get('idstr') if not ret: raise ProviderException("Missing 'idstr'") return ret
def extract_uid(self, data): if 'sub' not in data: raise ProviderException('QBO error', data) return str(data['sub'])
def extract_uid(self, data): if "id" not in data: raise ProviderException( "LinkedIn encountered an internal error while logging in. \ Please try again.") return str(data["id"])
def extract_uid(self, data): if "sub" not in data: raise ProviderException("QBO error", data) return str(data["sub"])