better ory-hydra error handling

master
tuxcoder 2023-12-23 02:41:39 +01:00
parent 632158b566
commit 04846aac0e
1 changed files with 4 additions and 1 deletions

View File

@ -1,5 +1,5 @@
from authlib.integrations.flask_client import OAuth
from authlib.integrations.base_client.errors import MismatchingStateError
from authlib.integrations.base_client.errors import MismatchingStateError, OAuthError
from flask import Flask, Blueprint, Response, session, request, redirect, url_for
from flask_login import login_user, logout_user, current_user
from flask.typing import ResponseReturnValue
@ -43,6 +43,9 @@ def authorized() -> ResponseReturnValue:
except MismatchingStateError:
logger.warning("MismatchingStateError redirect user")
return redirect(url_for('oauth2.login'))
except OAuthError as e:
logger.warning(f"OAuthError redirect user {e}")
return redirect(url_for('oauth2.login'))
if token is None:
return 'bad request', 400
session['token'] = token