async def refresh_token(Authorize: AuthJWT = Depends()): Authorize.jwt_refresh_token_required() current_user = Authorize.get_jwt_identity() ret = { 'access_token': AuthJWT.create_access_token(identity=current_user) } return ret
def refresh_token(Authorize: AuthJWT = Depends()): """ - Retreive current user using JWT token """ Authorize.jwt_refresh_token_required() current_user = Authorize.get_jwt_identity() ret = {'access_token': AuthJWT.create_access_token(identity=current_user)} return current_user
def protected(Authorize: AuthJWT = Depends()): # Protect an endpoint with jwt_required, which requires a valid access token # in the request to access. Authorize.jwt_required() # Access the identity of the current user with get_jwt_identity current_user = Authorize.get_jwt_identity() return {"logged_in_as": current_user}
def refresh(Authorize: AuthJWT = Depends()): Authorize.jwt_refresh_token_required() current_user = Authorize.get_jwt_identity() return { 'access_token': Authorize.create_access_token(identity=current_user, fresh=False) }
def protected(Authorize: AuthJWT = Depends()): Authorize.jwt_optional() # If no JWT is sent in with the request, get_jwt_identity() # will return None current_user = Authorize.get_jwt_identity() if current_user: return {"logged_in_as": current_user} else: return {"logged_in_as": "anonymous user"}
def protected(Authorize: AuthJWT = Depends()): Authorize.jwt_required() current_user = Authorize.get_jwt_identity() return {"logged_in_as": current_user}
async def update_user(user: UserUpdate, Authorize: AuthJWT = Depends()): Authorize.fresh_jwt_required() user_id = Authorize.get_jwt_identity() await UserCrud.update_user(user_id=user_id,**user.dict()) return {"message": "Success update your account."}
async def get_my_user(Authorize: AuthJWT = Depends()): Authorize.jwt_required() user_id = Authorize.get_jwt_identity() return await UserFetch.filter_by_id(id=user_id)
async def refresh_token(Authorize: AuthJWT = Depends()): Authorize.jwt_refresh_token_required() user_id = Authorize.get_jwt_identity() new_token = Authorize.create_access_token(identity=user_id,fresh=False) return {"access_token": new_token}
def get_jwt(Authorize: AuthJWT = Depends()): Authorize.jwt_required() # Access the identity of the current user with get_jwt_identity current_user = Authorize.get_jwt_identity() return {"logged_in_as": current_user}
def get_identity(Authorize: AuthJWT = Depends()): Authorize.jwt_required() return Authorize.get_jwt_identity()
def jwt_optional(Authorize: AuthJWT = Depends()): Authorize.jwt_optional() if Authorize.get_jwt_identity(): return {'hello': 'world'} return {'hello': 'anonym'}