def get_client(self, request, app): callback_url = reverse(self.adapter.provider_id + "_complete") callback_url = request.build_absolute_uri(callback_url) client = OAuth2Client(self.request, app.key, app.secret, self.adapter.authorize_url, self.adapter.access_token_url, callback_url) return client
def get_client(self, request, app): callback_url = reverse(self.adapter.provider_id + "_callback") callback_url = request.build_absolute_uri(callback_url) provider = self.adapter.get_provider() client = OAuth2Client(self.request, app.client_id, app.secret, self.adapter.access_token_url, callback_url, provider.get_scope()) return client
def get_client(self, request, app): callback_url = reverse(self.adapter.provider_id + "_callback") callback_url = build_absolute_uri( request, callback_url, protocol=self.adapter.redirect_uri_protocol) provider = self.adapter.get_provider() client = OAuth2Client(self.request, app.client_id, app.secret, self.adapter.access_token_method, self.adapter.access_token_url, callback_url, provider.get_scope(request)) return client
def get_client(self, request, app): callback_url = reverse(self.adapter.provider_id + "_callback") callback_url = request.build_absolute_uri(callback_url) client = OAuth2Client(self.request, app.key, app.secret, self.adapter.authorize_url, self.adapter.access_token_url, callback_url, self.adapter.get_provider().get_scope()) #print self.adapter.get_provider().get_scope() #print self.adapter.get_provider().id return client
def get_client(self, request, app): callback_url = self.adapter.get_callback_url(request, app) provider = self.adapter.get_provider() scope = provider.get_scope(request) client = OAuth2Client(self.request, app.client_id, app.secret, self.adapter.access_token_method, self.adapter.access_token_url, callback_url, scope, scope_delimiter=self.adapter.scope_delimiter, headers=self.adapter.headers, basic_auth=self.adapter.basic_auth) return client
def get_client(self, request, app): callback_url = reverse(self.adapter.provider_id + "_callback") protocol = (self.adapter.redirect_uri_protocol or app_settings.DEFAULT_HTTP_PROTOCOL) callback_url = build_absolute_uri( request, callback_url, protocol=protocol) provider = self.adapter.get_provider() scope = provider.get_scope(request) client = OAuth2Client(self.request, app.client_id, app.secret, self.adapter.access_token_method, self.adapter.access_token_url, callback_url, scope) return client
def oauth_callback(request, *args, **kwargs): try: is_google = request.GET['provider'] == 'google' adapter = GoogleOAuth2Adapter( request) if is_google else FacebookOAuth2Adapter(request) provider = adapter.get_provider() app = adapter.get_provider().get_app(request) try: if is_google: callback_url = adapter.get_callback_url(request, app) scope = provider.get_scope(request) client = OAuth2Client(request, app.client_id, app.secret, adapter.access_token_method, adapter.access_token_url, callback_url, scope, scope_delimiter=adapter.scope_delimiter, headers=adapter.headers, basic_auth=adapter.basic_auth) access_token = client.get_access_token(request.GET['code']) token = adapter.parse_token(access_token) else: access_token = request.GET['code'] token = adapter.parse_token({ 'access_token': access_token, 'token_type': 'bearer', 'expires_in': 5179237 }) # hard-coded properties to make allauth happy token.app = app login = adapter.complete_login(request, app, token, response=access_token) login.token = token return complete_social_login(request, login) except (PermissionDenied, OAuth2Error, RequestException, ProviderException) as e: return render_authentication_error(request, adapter.provider_id, exception=e) except ImmediateHttpResponse as e: return e.response
def get_client(self, request, app): callback_url = reverse(self.adapter.provider_id + "_callback") callback_url = build_absolute_uri( request, callback_url, protocol=self.adapter.redirect_uri_protocol) provider = self.adapter.get_provider() scope = provider.get_scope(request) client = OAuth2Client(self.request, app.client_id, app.secret, self.adapter.access_token_method, self.adapter.access_token_url, callback_url, scope, scope_delimiter=self.adapter.scope_delimiter, headers=self.adapter.headers, basic_auth=self.adapter.basic_auth, api_key=app.key) return client
def post(self, request, format=None): try: app = SocialApp.objects.get(provider="google") adapter = GoogleOAuth2Adapter(request) callback_url = 'http://localhost:3000' provider = adapter.get_provider() scope = provider.get_scope(request) client = OAuth2Client(self.request, app.client_id, app.secret, adapter.access_token_method, adapter.access_token_url, callback_url, scope, scope_delimiter=adapter.scope_delimiter, headers=adapter.headers, basic_auth=adapter.basic_auth) data = self.request.data code = data.get('code', '') access_token = client.get_access_token(code) token = adapter.parse_token(access_token) token.app = app login = adapter.complete_login(request, app, token, response=access_token) login.token = token complete_social_login(request, login) logged_in_user = login.account.user token, created = TokenModel.objects.get_or_create( user=logged_in_user) return Response({"success": True, 'key': token.key}) except Exception as e: # FIXME: Catch only what is needed print(e) return Response({"erorr": True})
def wrap(qs: OAuth2Client): qs.__class__ = AdvancedRedirectOAuth2Client return qs