Skip to content

msaUtils Module

.token


Attributes

oauth2_scheme module-attribute

oauth2_scheme = OAuth2PasswordBearer(tokenUrl='login')

Classes

MSAToken

Attributes

algorithm instance-attribute
algorithm: str = algorithm
credentials_exception instance-attribute
credentials_exception = HTTPException(
    status_code=status.HTTP_401_UNAUTHORIZED,
    detail="Could not validate credentials",
    headers={"WWW-Authenticate": "Bearer"},
)
secret_key instance-attribute
secret_key: str = secret_key

Functions

__init__
__init__(secret_key: str, algorithm: str = 'HS256')

MSAToken

PARAMETER DESCRIPTION
secret_key

The secret key to produce a Token

TYPE: str

algorithm

Algo to use, default HS256

TYPE: str DEFAULT: 'HS256'

create_token async
create_token(data: dict, expire_minutes: int = 100) -> str

Create a Token

PARAMETER DESCRIPTION
data

the data and content used to build the token

TYPE: dict

expire_minutes

the time the token is valid, expires

TYPE: int DEFAULT: 100

RETURNS DESCRIPTION
encoded_jwt

jwt encoded token

TYPE: str

get_current_user async
get_current_user(
    token: str = Depends(oauth2_scheme),
) -> MSATokenData
verify_token async
verify_token(token: str) -> MSATokenData

Verify Token

PARAMETER DESCRIPTION
token

the token as str

TYPE: str

RAISES DESCRIPTION
JWTError

credentials_exception

RETURNS DESCRIPTION
token_data

the jwt decoded data

TYPE: MSATokenData

MSATokenData

Bases: BaseModel

TokenData schema

Attributes

id class-attribute
id: Optional[str]

User ID


Last update: September 24, 2022
Created: September 24, 2022