fix login that it not shows 500 when authentik is to slow
Build and Push Docker Container / build-and-push (push) Successful in 1m51s
Build and Push Docker Container / build-and-push (push) Successful in 1m51s
This commit is contained in:
@@ -20,9 +20,12 @@ REDIRECT_URI_SCHEME = os.getenv('REDIRECT_URI_SCHEME', 'http')
|
|||||||
|
|
||||||
async def get_oidc_metadata():
|
async def get_oidc_metadata():
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
|
try:
|
||||||
response = await client.get(OIDC_METADATA_URL)
|
response = await client.get(OIDC_METADATA_URL)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
return response.json()
|
return response.json()
|
||||||
|
except httpx.ReadTimeout:
|
||||||
|
return await get_oidc_metadata()
|
||||||
|
|
||||||
@auth_login_bp.route('/login', methods=['GET'])
|
@auth_login_bp.route('/login', methods=['GET'])
|
||||||
@auth_login_bp.route('/auth', methods=['GET'])
|
@auth_login_bp.route('/auth', methods=['GET'])
|
||||||
@@ -87,12 +90,18 @@ async def auth_callback():
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Exchange code for token
|
# Exchange code for token
|
||||||
|
token_fetched = False
|
||||||
|
while not token_fetched:
|
||||||
|
try:
|
||||||
token = await client.fetch_token(
|
token = await client.fetch_token(
|
||||||
metadata['token_endpoint'],
|
metadata['token_endpoint'],
|
||||||
code=code,
|
code=code,
|
||||||
grant_type='authorization_code'
|
grant_type='authorization_code'
|
||||||
)
|
)
|
||||||
await logger.debug(f'Auth Callback | token: {token}')
|
await logger.debug(f'Auth Callback | token: {token}')
|
||||||
|
token_fetched = True
|
||||||
|
except httpx.ReadTimeout:
|
||||||
|
pass
|
||||||
|
|
||||||
# Decode ID token
|
# Decode ID token
|
||||||
id_token = token.get('id_token')
|
id_token = token.get('id_token')
|
||||||
@@ -126,6 +135,7 @@ async def auth_callback():
|
|||||||
return await render_template('views/api/token.htm', error="You don't have Permissions to Access this API"), 403
|
return await render_template('views/api/token.htm', error="You don't have Permissions to Access this API"), 403
|
||||||
|
|
||||||
session['user'] = claims
|
session['user'] = claims
|
||||||
|
|
||||||
response = await make_response(redirect(url_for('side_main.index')))
|
response = await make_response(redirect(url_for('side_main.index')))
|
||||||
response.set_cookie('auth_id', '', max_age=0, httponly=True, secure=True, samesite='Lax')
|
response.set_cookie('auth_id', '', max_age=0, httponly=True, secure=True, samesite='Lax')
|
||||||
return response
|
return response
|
||||||
|
|||||||
Reference in New Issue
Block a user