def GET_refresh_token(self, *args, **kwargs): # pylint: disable=unused-argument """Generate a refresh token given a username""" username = request.GET['username'] try: account = Account._by_name(username) except NotFound: account = register(username, uuid4().hex, '127.0.0.1') # subscribe the user now because reddit does not have consistency across # its APIs on what it considers the user to be subscribed to if not account.has_subscribed: Subreddit.subscribe_defaults(account) account.has_subscribed = True account._commit() client_id = g.secrets['generate_refresh_token_client_id'] client = OAuth2Client.get_token(client_id) scope = OAuth2Scope(OAuth2Scope.FULL_ACCESS) user_id = account._id36 refresh_token = OAuth2RefreshToken._new( client_id=client._id, user_id=user_id, scope=scope, ) access_token = OAuth2AccessToken._new( client_id=client._id, user_id=user_id, scope=scope, device_id='device', ) return json.dumps(OAuth2AccessController._make_new_token_response(access_token, refresh_token))
def run(self, client_id): if not client_id: return self.error() client = OAuth2Client.get_token(client_id) if client: return client else: return self.error()
def _get_client_auth(self): auth = request.headers.get("Authorization") try: client_id, client_secret = parse_http_basic(auth) client = OAuth2Client.get_token(client_id) require(client) require(constant_time_compare(client.secret, client_secret)) return client except RequirementException: abort(401, headers=[("WWW-Authenticate", 'Basic realm="reddit"')])
def _get_client_auth(self): auth = request.headers.get("Authorization") try: auth_scheme, auth_token = require_split(auth, 2) require(auth_scheme.lower() == "basic") try: auth_data = base64.b64decode(auth_token) except TypeError: raise RequirementException client_id, client_secret = require_split(auth_data, 2, ":") client = OAuth2Client.get_token(client_id) require(client) require(client.secret == client_secret) return client except RequirementException: abort(401, headers=[("WWW-Authenticate", 'Basic realm="reddit"')])