forked from sr2/cloud-api
feat: sensical user invitation
Users can now be invited to an org by email. "Email" for now is "print to stdout" Resolves #12
This commit is contained in:
parent
1012947b67
commit
62c43ce883
5 changed files with 173 additions and 5 deletions
27
src/utils.py
Normal file
27
src/utils.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
from joserfc import jwt, jwk, errors
|
||||
|
||||
from auth.exceptions import UnauthorizedException
|
||||
from src.config import settings
|
||||
|
||||
|
||||
KEY = jwk.import_key(settings.SECRET_KEY.get_secret_value(), "oct")
|
||||
|
||||
|
||||
async def generate_jwt(claims):
|
||||
jwt_token = jwt.encode(header={"alg": "HS256"}, key=KEY, claims=claims)
|
||||
|
||||
return jwt_token
|
||||
|
||||
|
||||
async def decode_jwt(encoded):
|
||||
try:
|
||||
token = jwt.decode(encoded, key=KEY)
|
||||
return token.claims
|
||||
except errors.DecodeError:
|
||||
raise UnauthorizedException("Invalid JWS")
|
||||
|
||||
|
||||
async def send_email(recipient: str, subject: str, body: str):
|
||||
print(recipient)
|
||||
print(subject)
|
||||
print(body)
|
||||
Loading…
Add table
Add a link
Reference in a new issue