Files
boc/landvex/user-management/app/__pycache__/security.cpython-39.pyc
T

20 lines
3.0 KiB
Plaintext
Raw Normal View History

a
N1GjT
ã@s6dZddlmZmZddlmZmZddlmZddlm Z m
Z
ddl m Z ddl
mZddlmZeƒZe d gd
d Zeeed œd
dZeedœddZd(eeefeeedœddZeeefedœddZeeedœddZejdejdejdejdiZee dœd d!„Z!eeed"œd#d$„Z"ed%œd&d'„Z#dS))u@Säkerhetsfunktioner: lösenordshashning, JWT-hantering, roller.é)ÚdatetimeÚ timedelta)ÚOptionalÚUnion)ÚUUID)ÚjwtÚJWTError)Ú CryptContext)Ú get_settings)ÚUserRoleZbcryptÚauto)ZschemesZ
deprecated)Úplain_passwordÚhashed_passwordÚreturncCs t ||¡S©N)Ú pwd_contextZverify)r
r©rúapp/security.pyÚverify_passwordsr)ÚpasswordrcCs
t |¡Sr)rÚhash)rrrrÚget_password_hashsrN)ÚsubjectÚ
expires_deltarcCsN|rt ¡|}nt ¡ttjd}|t|ƒddœ}tj|tjtj d}|S)N)ZminutesÚaccess©ZexpÚsubÚtype©Ú algorithm)
rÚutcnowrÚsettingsZACCESS_TOKEN_EXPIRE_MINUTESÚstrrÚencodeÚ
SECRET_KEYÚ ALGORITHM)rrÚexpireÚ to_encodeÚ encoded_jwtrrrÚcreate_access_tokens r))rrcCs<t ¡ttjd}|t|ƒddœ}tj|tjtj d}|S)N)ZdaysZrefreshrr)
rr rr!ZREFRESH_TOKEN_EXPIRE_DAYSr"rr#r$r%)rr&r'r(rrrÚcreate_refresh_token#sr*)ÚtokenrcCs6ztj|tjtjgd}|WSty0YdS0dS)N)Z
algorithms)rÚdecoder!r$r%r)r+ZpayloadrrrÚ decode_token*s
 r-ééé)ÚrolercCs t |d¡S)Nr)ÚROLE_HIERARCHYÚget)r1rrrÚ
role_level<sr4)Ú manager_roleÚ target_rolercCst|ƒt|ƒkS)uLReturnerar True om manager_role har högre eller lika nivÃ¥ som target_role.)r4)r5r6rrrÚ
can_manage@sr7)Úmin_rolecs*ddlmmtdœfdd }|S)u5Factory för roll-krav. Används i dependency-kedjan.r)Ú
HTTPExceptionÚstatus©Zcurrent_user_rolecs,t|ƒtˆƒkr(ˆˆjdˆjdddS)NzRequires role z