mirror of
https://git.collinwebdesigns.de/oscar.krause/fastapi-dls.git
synced 2024-12-26 05:49:32 +03:00
main.py - fixed wrong "origin_ref" in CodeResponse
- fixed issue - removed the now unnecessary table "auth"
This commit is contained in:
parent
d6d4cbc74a
commit
a0b9eae15b
36
app/main.py
36
app/main.py
@ -201,16 +201,13 @@ async def auth_v1_code(request: Request):
|
||||
'iat': timegm(cur_time.timetuple()),
|
||||
'exp': timegm(expires.timetuple()),
|
||||
'challenge': j['code_challenge'],
|
||||
'origin_ref': j['code_challenge'],
|
||||
'origin_ref': j['origin_ref'],
|
||||
'key_ref': SITE_KEY_XID,
|
||||
'kid': SITE_KEY_XID
|
||||
}
|
||||
|
||||
auth_code = jws.sign(payload, key=jwt_encode_key, headers={'kid': payload.get('kid')}, algorithm=ALGORITHMS.RS256)
|
||||
|
||||
db['auth'].delete(origin_ref=origin_ref, expires={'<=': cur_time - delta})
|
||||
db['auth'].insert(dict(origin_ref=origin_ref, code_challenge=j['code_challenge'], expires=expires))
|
||||
|
||||
response = {
|
||||
"auth_code": auth_code,
|
||||
"sync_timestamp": cur_time.isoformat(),
|
||||
@ -228,10 +225,8 @@ async def auth_v1_token(request: Request):
|
||||
j = json.loads((await request.body()).decode('utf-8'))
|
||||
payload = jwt.decode(token=j['auth_code'], key=jwt_decode_key)
|
||||
|
||||
code_challenge = payload['origin_ref']
|
||||
|
||||
origin_ref = db['auth'].find_one(code_challenge=code_challenge)['origin_ref']
|
||||
logging.info(f'> [ auth ]: {origin_ref} ({code_challenge}): {j}')
|
||||
origin_ref = payload['origin_ref']
|
||||
logging.info(f'> [ auth ]: {origin_ref}: {j}')
|
||||
|
||||
# validate the code challenge
|
||||
if payload['challenge'] != b64enc(sha256(j['code_verifier'].encode('utf-8')).digest()).rstrip(b'=').decode('utf-8'):
|
||||
@ -246,7 +241,7 @@ async def auth_v1_token(request: Request):
|
||||
'iss': 'https://cls.nvidia.org',
|
||||
'aud': 'https://cls.nvidia.org',
|
||||
'exp': timegm(access_expires_on.timetuple()),
|
||||
'origin_ref': payload['origin_ref'],
|
||||
'origin_ref': origin_ref,
|
||||
'key_ref': SITE_KEY_XID,
|
||||
'kid': SITE_KEY_XID,
|
||||
}
|
||||
@ -267,12 +262,9 @@ async def auth_v1_token(request: Request):
|
||||
async def leasing_v1_lessor(request: Request):
|
||||
j, token = json.loads((await request.body()).decode('utf-8')), get_token(request)
|
||||
|
||||
code_challenge = token['origin_ref']
|
||||
origin_ref = token['origin_ref']
|
||||
scope_ref_list = j['scope_ref_list']
|
||||
|
||||
origin_ref = db['auth'].find_one(code_challenge=code_challenge)['origin_ref']
|
||||
|
||||
logging.info(f'> [ create ]: {origin_ref} ({code_challenge}): create leases for scope_ref_list {scope_ref_list}')
|
||||
logging.info(f'> [ create ]: {origin_ref}: create leases for scope_ref_list {scope_ref_list}')
|
||||
|
||||
cur_time = datetime.utcnow()
|
||||
lease_result_list = []
|
||||
@ -311,11 +303,10 @@ async def leasing_v1_lessor(request: Request):
|
||||
async def leasing_v1_lessor_lease(request: Request):
|
||||
token = get_token(request)
|
||||
|
||||
code_challenge = token['origin_ref']
|
||||
origin_ref = token['origin_ref']
|
||||
|
||||
origin_ref = db['auth'].find_one(code_challenge=code_challenge)['origin_ref']
|
||||
active_lease_list = list(map(lambda x: x['lease_ref'], db['lease'].find(origin_ref=origin_ref)))
|
||||
logging.info(f'> [ leases ]: {origin_ref} ({code_challenge}): found {len(active_lease_list)} active leases')
|
||||
logging.info(f'> [ leases ]: {origin_ref}: found {len(active_lease_list)} active leases')
|
||||
|
||||
cur_time = datetime.utcnow()
|
||||
response = {
|
||||
@ -332,10 +323,8 @@ async def leasing_v1_lessor_lease(request: Request):
|
||||
async def leasing_v1_lease_renew(request: Request, lease_ref: str):
|
||||
token = get_token(request)
|
||||
|
||||
code_challenge = token['origin_ref']
|
||||
|
||||
origin_ref = db['auth'].find_one(code_challenge=code_challenge)['origin_ref']
|
||||
logging.info(f'> [ renew ]: {origin_ref} ({code_challenge}): renew {lease_ref}')
|
||||
origin_ref = token['origin_ref']
|
||||
logging.info(f'> [ renew ]: {origin_ref}: renew {lease_ref}')
|
||||
|
||||
if db['lease'].count(origin_ref=origin_ref, lease_ref=lease_ref) == 0:
|
||||
raise HTTPException(status_code=404, detail='requested lease not available')
|
||||
@ -361,12 +350,11 @@ async def leasing_v1_lease_renew(request: Request, lease_ref: str):
|
||||
async def leasing_v1_lessor_lease_remove(request: Request):
|
||||
token = get_token(request)
|
||||
|
||||
code_challenge = token['origin_ref']
|
||||
origin_ref = token['origin_ref']
|
||||
|
||||
origin_ref = db['auth'].find_one(code_challenge=code_challenge)['origin_ref']
|
||||
released_lease_list = list(map(lambda x: x['lease_ref'], db['lease'].find(origin_ref=origin_ref)))
|
||||
deletions = db['lease'].delete(origin_ref=origin_ref)
|
||||
logging.info(f'> [ remove ]: {origin_ref} ({code_challenge}): removed {deletions} leases')
|
||||
logging.info(f'> [ remove ]: {origin_ref}: removed {deletions} leases')
|
||||
|
||||
cur_time = datetime.utcnow()
|
||||
response = {
|
||||
|
Loading…
Reference in New Issue
Block a user