def authorized_token(self, token, verifier=None): """ authorize token verify OAuth set OAuth client post OAuth content response not 200 raise unknown response return OAuth token as string """ parameters = {} if verifier: parameters.update({ "oauth_verifier": verifier, }) client = oauth.Client(self.consumer, token=token) logger.debug("OAuthAccess.authorized_token: params: %s" % parameters) response, content = client.request( self.access_token_url, method="POST", # parameters must be urlencoded (which are then re-decoded by # oauth2 -- seems lame) body=urllib.urlencode(parameters), ) if response["status"] != "200": raise UnknownResponse( "Got %s from %s:\n\n%s" % (response["status"], self.access_token_url, content)) logger.debug("OAuthAccess.authorized_token: response from %s: %s" % (self.access_token_url, content)) return oauth.Token.from_string(content)
def fetch_unauthorized_token(self): """ This function may further handle when a user does not authorize the app to access their facebook information. """ #@TODO - Can we delete this too? parameters = { "oauth_callback": self.callback_url, } client = oauth.Client(self.consumer) response, content = client.request( self.request_token_url, method="POST", # parameters must be urlencoded (which are then re-decoded by # and re-encoded by oauth2 -- seems lame) body=urllib.urlencode(parameters), ) if response["status"] != "200": raise UnknownResponse( "Got %s from %s:\n\n%s" % (response["status"], self.request_token_url, content)) return oauth.Token.from_string(content)