Exemplo n.º 1
0
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
Exemplo n.º 3
0
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"}
Exemplo n.º 6
0
def protected(Authorize: AuthJWT = Depends()):
    Authorize.jwt_required()

    current_user = Authorize.get_jwt_identity()
    return {"logged_in_as": current_user}
Exemplo n.º 7
0
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."}
Exemplo n.º 8
0
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)
Exemplo n.º 9
0
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}
Exemplo n.º 10
0
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}
Exemplo n.º 11
0
 def get_identity(Authorize: AuthJWT = Depends()):
     Authorize.jwt_required()
     return Authorize.get_jwt_identity()
Exemplo n.º 12
0
 def jwt_optional(Authorize: AuthJWT = Depends()):
     Authorize.jwt_optional()
     if Authorize.get_jwt_identity():
         return {'hello': 'world'}
     return {'hello': 'anonym'}