def reddit_get_token(): access_args = { 'code': flask.request.args.get('code'), 'client_id': reddit.consumer_key, 'client_secret': reddit.consumer_secret, 'redirect_uri': flask.session.get(reddit.name + '_oauthredir'), } access_args.update(reddit.access_token_params) auth = 'Basic ' + b64encode( ('%s:%s' % (reddit.consumer_key, reddit.consumer_secret)).encode( 'latin1')).strip().decode('latin1') resp, content = reddit._client.request( reddit.expand_url(reddit.access_token_url), reddit.access_token_method, urls.url_encode(access_args), headers={'Authorization': auth}, ) data = oauth.parse_response(resp, content) if not reddit.status_okay(resp): raise oauth.OAuthException( 'Invalid response from ' + reddit.name, type='invalid_response', data=data, ) return data
def handle_oauth1_response(self): """ Handles an oauth1 authorization response. The return value of this method is forwarded as the first argument to the handling view function. """ client = self.make_client() resp, content = client.request( "{0}&oauth_verifier={1}".format(self.expand_url(self.access_token_url), request.args["oauth_verifier"]), self.access_token_method, ) data = nasty_patch_to_oauth.parse_response(resp, content) if not self.status_okay(resp): raise OAuthException("Invalid response from " + self.name, type="invalid_response", data=data) return data