Example #1
0
 def dispatch(self, request):
     if 'error' in request.GET or not 'code' in request.GET:
         # TODO: Distinguish cancel from error
         return render_authentication_error(request)
         #app = self.adapter.get_provider().get_app(self.request)
     client = self.get_client(request)
     try:
         access_token = client.get_access_token(request.GET['code'])
         token = self.adapter.parse_token(access_token)
         #token.app = app
         login = self.adapter.complete_login(request,
                                             token,
                                             response=access_token)
         token.account = login.account
         login.token = token
         if self.adapter.supports_state:
             login.state = SocialLogin \
                 .verify_and_unstash_state(
                 request,
                 request.REQUEST.get('state'))
         else:
             login.state = SocialLogin.unstash_state(request)
         return complete_social_login(request, login)
     except OAuth2Error:
         return render_authentication_error(request)
Example #2
0
 def dispatch(self, request):
     provider = self.adapter.get_provider()
     client = self.get_client(request)
     action = request.GET.get('action', AuthAction.AUTHENTICATE)
     auth_url = self.adapter.authorize_url
     # auth_params = provider.get_auth_params(request, action)
     client.state = SocialLogin.stash_state(request)
     try:
         return HttpResponseRedirect(client.get_redirect_url(auth_url, ''))
     except OAuth2Error:
         return render_authentication_error(request)
Example #3
0
def login_by_token(request):
    ret = None
    if request.method == 'POST':
        form = FacebookConnectForm(request.POST)
        if form.is_valid():
            try:
                app = providers.registry.by_id(FacebookProvider.id) \
                    .get_app(request)
                access_token = form.cleaned_data['access_token']
                token = SocialToken(app=app,
                                    token=access_token)
                login = fb_complete_login(request, app, token)
                login.token = token
                login.state = SocialLogin.state_from_request(request)
                ret = complete_social_login(request, login)
            except:
                # FIXME: Catch only what is needed
                pass
    if not ret:
        ret = render_authentication_error(request)
    return ret