def authenticate(self, *args, **kwargs): request = kwargs["request"] self.session = self.backend.get_session(**{self.backend_name: request}) user = authenticate(**{self.backend_name: self.session}) if user: login(request, user) return redirect(reverse(settings_getattr(LOGIN_OK_KEY))) resolve_user = settings_getattr(RESOLVE_FORM_KEY) if not resolve_user: return redirect(reverse(settings_getattr(LOGIN_ERROR_KEY))) return redirect(reverse(resolve_user))
def get_login_url(self, request): params = [ "client_id=%s" % self.get_client_key(), "redirect_uri=%s" % self.get_redirect_url(request) ] if hasattr(settings, FACEBOOK_SCOPE): params.append("scope=%s" % settings_getattr(FACEBOOK_SCOPE)) param_str = "&".join(params) return "https://www.facebook.com/dialog/oauth?%s" % param_str
def test_permission_denied(self): u""" Если при попытке получить объект сессии возникает исключение PermissionDenied, то делаем редирект на страницу ошибки. """ workflow = LoginWorkflow('facebook') with patch.object(workflow, 'backend') as mock: mock.configure_mock(**{ 'get_session.side_effect': PermissionDeniedException }) result = workflow.authenticate(**{'request': None}) self.assertEquals(result['Location'], reverse(settings_getattr(LOGIN_ERROR_KEY))+'?error=permission%20denied')
def callback(request, backend_name): try: workflow = get_workflow(request) if workflow.backend_name != backend_name: raise AkamaruError("Workflow") except AkamaruError: traceback.print_exc(file=sys.stdout) if AKAMARU_ILLEGAL_STATE_REDIRECT in settings: akamaru_illegal_state_redirect = settings_getattr(AKAMARU_ILLEGAL_STATE_REDIRECT) return HttpResponseRedirect(akamaru_illegal_state_redirect) return HttpResponseRedirect('/') request.session.modified = True return workflow.authenticate(**{'request': request})
def get_client_secret(self): return settings_getattr(FACEBOOK_SECRET_KEY)
def get_client_key(self): return settings_getattr(FACEBOOK_APP_ID_KEY)
def get_client_secret(self): return settings_getattr('TRELLO_TOKEN')
def get_client_key(self): return settings_getattr('TRELLO_API_KEY')
def get_client_secret(self): return settings_getattr(GOOGLE_CONSUMER_SECRET_KEY)
def get_client_key(self): return settings_getattr(GOOGLE_CONSUMER_KEY_KEY)
def get_client_secret(self): return settings_getattr(VKONTAKTE_SECRET_KEY)
def get_client_key(self): return settings_getattr(VKONTAKTE_APP_ID_KEY)
def get_scope(self): try: return settings_getattr(VKONTAKTE_SCOPE) except: return ''