add async handling
This commit is contained in:
parent
bfdd924b6f
commit
2a119b6ef8
|
@ -37,12 +37,12 @@ admin_views.before_request(before_request)
|
||||||
|
|
||||||
|
|
||||||
@admin_views.route('/', methods=['GET', 'POST'])
|
@admin_views.route('/', methods=['GET', 'POST'])
|
||||||
def index() -> ResponseReturnValue:
|
async def index() -> ResponseReturnValue:
|
||||||
return render_template('admin/index.html.j2')
|
return render_template('admin/index.html.j2')
|
||||||
|
|
||||||
|
|
||||||
@admin_views.route('/user', methods=['GET'])
|
@admin_views.route('/user', methods=['GET'])
|
||||||
def users():
|
async def users():
|
||||||
users = User.query.all()
|
users = User.query.all()
|
||||||
return render_template('admin/users.html.j2', users=users)
|
return render_template('admin/users.html.j2', users=users)
|
||||||
|
|
||||||
|
@ -76,14 +76,14 @@ def registration_accept(registration_id) -> ResponseReturnValue:
|
||||||
|
|
||||||
|
|
||||||
@admin_views.route('/clients')
|
@admin_views.route('/clients')
|
||||||
def clients() -> ResponseReturnValue:
|
async def clients() -> ResponseReturnValue:
|
||||||
clients = list_o_auth_2_clients.sync(_client=hydra_service.hydra_client)
|
clients = await list_o_auth_2_clients.asyncio(_client=hydra_service.hydra_client)
|
||||||
return render_template('admin/clients.html.j2', clients=clients)
|
return render_template('admin/clients.html.j2', clients=clients)
|
||||||
|
|
||||||
@admin_views.route('/client/<client_id>', methods=['GET', 'POST'])
|
@admin_views.route('/client/<client_id>', methods=['GET', 'POST'])
|
||||||
def client(client_id: str) -> ResponseReturnValue:
|
async def client(client_id: str) -> ResponseReturnValue:
|
||||||
|
|
||||||
client = get_o_auth_2_client.sync(client_id, _client=hydra_service.hydra_client)
|
client = await get_o_auth_2_client.asyncio(client_id, _client=hydra_service.hydra_client)
|
||||||
if client is None or isinstance( client, GenericError):
|
if client is None or isinstance( client, GenericError):
|
||||||
logger.error(f"oauth2 client not found with id: '{client_id}'")
|
logger.error(f"oauth2 client not found with id: '{client_id}'")
|
||||||
return 'client not found', 404
|
return 'client not found', 404
|
||||||
|
@ -92,7 +92,7 @@ def client(client_id: str) -> ResponseReturnValue:
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
form.populate_obj(client)
|
form.populate_obj(client)
|
||||||
|
|
||||||
client = update_o_auth_2_client.sync(id=client_id ,json_body=client, _client=hydra_service.hydra_client)
|
client = await update_o_auth_2_client.asyncio(id=client_id ,json_body=client, _client=hydra_service.hydra_client)
|
||||||
if client is None or isinstance(client, GenericError):
|
if client is None or isinstance(client, GenericError):
|
||||||
logger.error(f"oauth2 client update failed: '{client_id}'")
|
logger.error(f"oauth2 client update failed: '{client_id}'")
|
||||||
return 'client update failed', 500
|
return 'client update failed', 500
|
||||||
|
@ -103,7 +103,7 @@ def client(client_id: str) -> ResponseReturnValue:
|
||||||
|
|
||||||
|
|
||||||
@admin_views.route('/client_new', methods=['GET','POST'])
|
@admin_views.route('/client_new', methods=['GET','POST'])
|
||||||
def client_new() -> ResponseReturnValue:
|
async def client_new() -> ResponseReturnValue:
|
||||||
|
|
||||||
client = OAuth2Client()
|
client = OAuth2Client()
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ def client_new() -> ResponseReturnValue:
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
form.populate_obj(client)
|
form.populate_obj(client)
|
||||||
|
|
||||||
resp_client = create_o_auth_2_client.sync(json_body=client, _client=hydra_service.hydra_client)
|
resp_client = await create_o_auth_2_client.asyncio(json_body=client, _client=hydra_service.hydra_client)
|
||||||
if resp_client is None:
|
if resp_client is None:
|
||||||
logger.error(f"oauth2 client update failed: '{client.client_id}'")
|
logger.error(f"oauth2 client update failed: '{client.client_id}'")
|
||||||
return 'internal error', 500
|
return 'internal error', 500
|
||||||
|
|
|
@ -35,7 +35,7 @@ auth_views = Blueprint('auth', __name__, url_prefix='/auth')
|
||||||
|
|
||||||
|
|
||||||
@auth_views.route('/consent', methods=['GET', 'POST'])
|
@auth_views.route('/consent', methods=['GET', 'POST'])
|
||||||
def consent() -> ResponseReturnValue:
|
async def consent() -> ResponseReturnValue:
|
||||||
"""Always grant consent."""
|
"""Always grant consent."""
|
||||||
# DUMMPY ONLY
|
# DUMMPY ONLY
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ def consent() -> ResponseReturnValue:
|
||||||
remember_for = 60*60*24*30 # remember for 30 days
|
remember_for = 60*60*24*30 # remember for 30 days
|
||||||
|
|
||||||
#try:
|
#try:
|
||||||
consent_request = get_consent_request.sync(consent_challenge=request.args['consent_challenge'],_client=hydra_service.hydra_client)
|
consent_request = await get_consent_request.asyncio(consent_challenge=request.args['consent_challenge'],_client=hydra_service.hydra_client)
|
||||||
|
|
||||||
if consent_request is None or isinstance( consent_request, GenericError):
|
if consent_request is None or isinstance( consent_request, GenericError):
|
||||||
return redirect(url_for('frontend.index'))
|
return redirect(url_for('frontend.index'))
|
||||||
|
@ -83,7 +83,7 @@ def consent() -> ResponseReturnValue:
|
||||||
id_token= id_token
|
id_token= id_token
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
resp = accept_consent_request.sync(_client=hydra_service.hydra_client,
|
resp = await accept_consent_request.asyncio(_client=hydra_service.hydra_client,
|
||||||
json_body=body,
|
json_body=body,
|
||||||
consent_challenge=consent_request.challenge)
|
consent_challenge=consent_request.challenge)
|
||||||
if resp is None or isinstance( resp, GenericError):
|
if resp is None or isinstance( resp, GenericError):
|
||||||
|
@ -98,17 +98,17 @@ def consent() -> ResponseReturnValue:
|
||||||
|
|
||||||
|
|
||||||
@auth_views.route('/login', methods=['GET', 'POST'])
|
@auth_views.route('/login', methods=['GET', 'POST'])
|
||||||
def login() -> ResponseReturnValue:
|
async def login() -> ResponseReturnValue:
|
||||||
login_challenge = request.args.get('login_challenge')
|
login_challenge = request.args.get('login_challenge')
|
||||||
if login_challenge is None:
|
if login_challenge is None:
|
||||||
return 'login_challenge missing', 400
|
return 'login_challenge missing', 400
|
||||||
login_request = get_login_request.sync(_client=hydra_service.hydra_client, login_challenge=login_challenge)
|
login_request = await get_login_request.asyncio(_client=hydra_service.hydra_client, login_challenge=login_challenge)
|
||||||
if login_request is None or isinstance( login_request, GenericError):
|
if login_request is None or isinstance( login_request, GenericError):
|
||||||
logger.exception("could not fetch login request")
|
logger.exception("could not fetch login request")
|
||||||
return redirect(url_for('frontend.index'))
|
return redirect(url_for('frontend.index'))
|
||||||
|
|
||||||
if login_request.skip:
|
if login_request.skip:
|
||||||
resp = accept_login_request.sync(_client=hydra_service.hydra_client,
|
resp = await accept_login_request.asyncio(_client=hydra_service.hydra_client,
|
||||||
login_challenge=login_challenge,
|
login_challenge=login_challenge,
|
||||||
json_body=AcceptLoginRequest(subject=login_request.subject))
|
json_body=AcceptLoginRequest(subject=login_request.subject))
|
||||||
if resp is None or isinstance( resp, GenericError):
|
if resp is None or isinstance( resp, GenericError):
|
||||||
|
@ -129,11 +129,11 @@ def login() -> ResponseReturnValue:
|
||||||
|
|
||||||
|
|
||||||
@auth_views.route('/login/auth', methods=['GET', 'POST'])
|
@auth_views.route('/login/auth', methods=['GET', 'POST'])
|
||||||
def login_auth() -> ResponseReturnValue:
|
async def login_auth() -> ResponseReturnValue:
|
||||||
login_challenge = request.args.get('login_challenge')
|
login_challenge = request.args.get('login_challenge')
|
||||||
if login_challenge is None:
|
if login_challenge is None:
|
||||||
return 'missing login_challenge, bad request', 400
|
return 'missing login_challenge, bad request', 400
|
||||||
login_request = get_login_request.sync(_client=hydra_service.hydra_client, login_challenge=login_challenge)
|
login_request = await get_login_request.asyncio(_client=hydra_service.hydra_client, login_challenge=login_challenge)
|
||||||
if login_request is None:
|
if login_request is None:
|
||||||
return redirect(url_for('frontend.index'))
|
return redirect(url_for('frontend.index'))
|
||||||
|
|
||||||
|
@ -160,7 +160,7 @@ def login_auth() -> ResponseReturnValue:
|
||||||
subject = user.id
|
subject = user.id
|
||||||
user.last_login = datetime.now()
|
user.last_login = datetime.now()
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
resp = accept_login_request.sync(_client=hydra_service.hydra_client,
|
resp = await accept_login_request.asyncio(_client=hydra_service.hydra_client,
|
||||||
login_challenge=login_challenge, json_body=AcceptLoginRequest(
|
login_challenge=login_challenge, json_body=AcceptLoginRequest(
|
||||||
subject=subject,
|
subject=subject,
|
||||||
remember=remember_me,
|
remember=remember_me,
|
||||||
|
@ -172,12 +172,12 @@ def login_auth() -> ResponseReturnValue:
|
||||||
|
|
||||||
|
|
||||||
@auth_views.route("/logout")
|
@auth_views.route("/logout")
|
||||||
def logout() -> ResponseReturnValue:
|
async def logout() -> ResponseReturnValue:
|
||||||
logout_challenge = request.args.get('logout_challenge')
|
logout_challenge = request.args.get('logout_challenge')
|
||||||
if logout_challenge is None:
|
if logout_challenge is None:
|
||||||
return 'invalid request, logout_challenge not set', 400
|
return 'invalid request, logout_challenge not set', 400
|
||||||
# TODO confirm
|
# TODO confirm
|
||||||
resp = accept_logout_request.sync(_client=hydra_service.hydra_client, logout_challenge=logout_challenge)
|
resp = await accept_logout_request.asyncio(_client=hydra_service.hydra_client, logout_challenge=logout_challenge)
|
||||||
if resp is None or isinstance( resp, GenericError):
|
if resp is None or isinstance( resp, GenericError):
|
||||||
return 'internal error, could not forward request', 503
|
return 'internal error, could not forward request', 503
|
||||||
return redirect(resp.redirect_to)
|
return redirect(resp.redirect_to)
|
||||||
|
|
Loading…
Reference in a new issue