def set_token(token, request, *args, **kwargs): with faf.db.connection: # make sure that every client has only one token connected to a user OAuthToken.delete(request.client.client_id, current_user.id) expires_in = token.get('expires_in') expires = datetime.utcnow() + timedelta(seconds=expires_in) return OAuthToken.insert( access_token=token['access_token'], # TODO: Support refresh token? refresh_token=token.get('refresh_token', ''), token_type=token['token_type'], scope=token.scope, expires=expires, client_id=request.client.client_id, user_id=current_user.id)
def set_token(token, request, *args, **kwargs): with faf.db.connection: # make sure that every client has only one token connected to a user OAuthToken.delete(request.client.client_id, current_user.id) expires_in = token.get('expires_in') expires = datetime.utcnow() + timedelta(seconds=expires_in) return OAuthToken.insert( access_token=token['access_token'], # TODO: Support refresh token? refresh_token=token.get('refresh_token', ''), token_type=token['token_type'], scope=token.scope, expires=expires, client_id=request.client.client_id, user_id=current_user.id )
def set_token(token, request, *args, **kwargs): # https://github.com/lepture/flask-oauthlib/issues/209 user_id = request.user.id if hasattr(request.user, 'id') else current_user.id # make sure that every client has only one token connected to a user OAuthToken.delete(request.client.client_id, user_id) with faf.db.connection: expires_in = token.get('expires_in') expires = datetime.utcnow() + timedelta(seconds=expires_in) return OAuthToken.insert( access_token=token['access_token'], # TODO: Support refresh token? refresh_token=token.get('refresh_token', ''), token_type=token['token_type'], scope=token.scope, expires=expires, client_id=request.client.client_id, user_id=user_id )