def oauth_redirect(request): oa = OAuthClient( url=getattr(settings, "SMARTFILE_API_URL", None), client_token=getattr(settings, "SMARTFILE_CLIENT_TOKEN", None), client_secret=getattr(settings, "SMARTFILE_CLIENT_SECRET", None), ) rt = request.session["SMARTFILE_REQUEST_TOKEN"] = oa.get_request_token( callback=request.build_absolute_uri(reverse("oauth_callback")) ) return redirect(oa.get_authorization_url(rt))
def oauth_callback(request): verifier = request.GET.get("verifier") oa = OAuthClient( url=getattr(settings, "SMARTFILE_API_URL", None), client_token=getattr(settings, "SMARTFILE_CLIENT_TOKEN", None), client_secret=getattr(settings, "SMARTFILE_CLIENT_SECRET", None), ) try: rt = request.session.pop("SMARTFILE_REQUEST_TOKEN") except KeyError: return redirect(reverse("oauth_redirect")) at = request.session["SMARTFILE_ACCESS_TOKEN"] = oa.get_access_token(rt, verifier=verifier) return redirect(reverse("verify"))
def getClient(self, **kwargs): kwargs.setdefault('client_token', CLIENT_TOKEN) kwargs.setdefault('client_secret', CLIENT_SECRET) kwargs.setdefault('access_token', ACCESS_TOKEN) kwargs.setdefault('access_secret', ACCESS_SECRET) kwargs.setdefault('url', 'http://127.0.0.1:%s/' % self.server.server_port) return OAuthClient(**kwargs)