class OauthResource(Resource): def __init__(self, realm='OAuth', auth_template='webmachine/authorize_token.html', auth_form=OAuthAuthenticationForm): self.auth_template = auth_template self.auth_form = auth_form self.realm = realm oauth_datastore = load_oauth_datastore() self.oauth_server = OAuthServer(oauth_datastore()) self.oauth_server.add_signature_method( oauth2.SignatureMethod_PLAINTEXT()) self.oauth_server.add_signature_method( oauth2.SignatureMethod_HMAC_SHA1()) def allowed_methods(self, req, resp): return ["GET", "HEAD", "POST"] def oauth_authorize(self, req, resp): try: token = self.oauth_server.fetch_request_token(req.oauth_request) except oauth2.Error, err: return self.auth_error(req, resp, err) try: callback = self.auth_server.get_callback(req.oauth_request) except: callback = None if req.method == "GET": params = req.oauth_request.get_normalized_parameters() form = self.auth_form( initial={ 'oauth_token': token.key, 'oauth_callback': token.get_callback_url() or callback, }) resp.content = loader.render_to_string(self.auth_template, {'form': form}, RequestContext(req)) elif req.method == "POST": try: form = self.auth_form(req.POST) if form.is_valid(): token = self.oauth_server.authorize_token(token, req.user) args = '?' + token.to_string(only_key=True) else: args = '?error=%s' % 'Access not granted by user.' if not callback: resp.content = 'Access not granted by user.' if not callback: return True resp.redirect_to = iri_to_uri("%s%s" % (callback, args)) except oauth2.Error, err: return self.oauth_error(req, resp, err)
class OauthResource(Resource): def __init__( self, realm="OAuth", auth_template="webmachine/authorize_token.html", auth_form=OAuthAuthenticationForm ): self.auth_template = auth_template self.auth_form = auth_form self.realm = realm oauth_datastore = load_oauth_datastore() self.oauth_server = OAuthServer(oauth_datastore()) self.oauth_server.add_signature_method(oauth2.SignatureMethod_PLAINTEXT()) self.oauth_server.add_signature_method(oauth2.SignatureMethod_HMAC_SHA1()) def allowed_methods(self, req, resp): return ["GET", "HEAD", "POST"] def oauth_authorize(self, req, resp): try: token = self.oauth_server.fetch_request_token(req.oauth_request) except oauth2.Error, err: return self.auth_error(req, resp, err) try: callback = self.auth_server.get_callback(req.oauth_request) except: callback = None if req.method == "GET": params = req.oauth_request.get_normalized_parameters() form = self.auth_form( initial={"oauth_token": token.key, "oauth_callback": token.get_callback_url() or callback} ) resp.content = loader.render_to_string(self.auth_template, {"form": form}, RequestContext(req)) elif req.method == "POST": try: form = self.auth_form(req.POST) if form.is_valid(): token = self.oauth_server.authorize_token(token, req.user) args = "?" + token.to_string(only_key=True) else: args = "?error=%s" % "Access not granted by user." if not callback: resp.content = "Access not granted by user." if not callback: return True resp.redirect_to = iri_to_uri("%s%s" % (callback, args)) except oauth2.Error, err: return self.oauth_error(req, resp, err)
def __init__(self, realm='OAuth', auth_template='webmachine/authorize_token.html', auth_form=OAuthAuthenticationForm): self.auth_template = auth_template self.auth_form = auth_form self.realm = realm oauth_datastore = load_oauth_datastore() self.oauth_server = OAuthServer(oauth_datastore()) self.oauth_server.add_signature_method( oauth2.SignatureMethod_PLAINTEXT()) self.oauth_server.add_signature_method( oauth2.SignatureMethod_HMAC_SHA1())
def __init__( self, realm="OAuth", auth_template="webmachine/authorize_token.html", auth_form=OAuthAuthenticationForm ): self.auth_template = auth_template self.auth_form = auth_form self.realm = realm oauth_datastore = load_oauth_datastore() self.oauth_server = OAuthServer(oauth_datastore()) self.oauth_server.add_signature_method(oauth2.SignatureMethod_PLAINTEXT()) self.oauth_server.add_signature_method(oauth2.SignatureMethod_HMAC_SHA1())