add async handling

This commit is contained in:
TuxCoder 2022-02-20 16:53:24 +01:00
parent bfdd924b6f
commit 2a119b6ef8
2 changed files with 20 additions and 20 deletions

View file

@ -37,12 +37,12 @@ admin_views.before_request(before_request)
@admin_views.route('/', methods=['GET', 'POST'])
def index() -> ResponseReturnValue:
async def index() -> ResponseReturnValue:
return render_template('admin/index.html.j2')
@admin_views.route('/user', methods=['GET'])
def users():
async def users():
users = User.query.all()
return render_template('admin/users.html.j2', users=users)
@ -76,14 +76,14 @@ def registration_accept(registration_id) -> ResponseReturnValue:
@admin_views.route('/clients')
def clients() -> ResponseReturnValue:
clients = list_o_auth_2_clients.sync(_client=hydra_service.hydra_client)
async def clients() -> ResponseReturnValue:
clients = await list_o_auth_2_clients.asyncio(_client=hydra_service.hydra_client)
return render_template('admin/clients.html.j2', clients=clients)
@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):
logger.error(f"oauth2 client not found with id: '{client_id}'")
return 'client not found', 404
@ -92,7 +92,7 @@ def client(client_id: str) -> ResponseReturnValue:
if form.validate_on_submit():
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):
logger.error(f"oauth2 client update failed: '{client_id}'")
return 'client update failed', 500
@ -103,7 +103,7 @@ def client(client_id: str) -> ResponseReturnValue:
@admin_views.route('/client_new', methods=['GET','POST'])
def client_new() -> ResponseReturnValue:
async def client_new() -> ResponseReturnValue:
client = OAuth2Client()
@ -111,7 +111,7 @@ def client_new() -> ResponseReturnValue:
if form.validate_on_submit():
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:
logger.error(f"oauth2 client update failed: '{client.client_id}'")
return 'internal error', 500

View file

@ -35,7 +35,7 @@ auth_views = Blueprint('auth', __name__, url_prefix='/auth')
@auth_views.route('/consent', methods=['GET', 'POST'])
def consent() -> ResponseReturnValue:
async def consent() -> ResponseReturnValue:
"""Always grant consent."""
# DUMMPY ONLY
@ -43,7 +43,7 @@ def consent() -> ResponseReturnValue:
remember_for = 60*60*24*30 # remember for 30 days
#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):
return redirect(url_for('frontend.index'))
@ -83,7 +83,7 @@ def consent() -> ResponseReturnValue:
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,
consent_challenge=consent_request.challenge)
if resp is None or isinstance( resp, GenericError):
@ -98,17 +98,17 @@ def consent() -> ResponseReturnValue:
@auth_views.route('/login', methods=['GET', 'POST'])
def login() -> ResponseReturnValue:
async def login() -> ResponseReturnValue:
login_challenge = request.args.get('login_challenge')
if login_challenge is None:
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):
logger.exception("could not fetch login request")
return redirect(url_for('frontend.index'))
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,
json_body=AcceptLoginRequest(subject=login_request.subject))
if resp is None or isinstance( resp, GenericError):
@ -129,11 +129,11 @@ def login() -> ResponseReturnValue:
@auth_views.route('/login/auth', methods=['GET', 'POST'])
def login_auth() -> ResponseReturnValue:
async def login_auth() -> ResponseReturnValue:
login_challenge = request.args.get('login_challenge')
if login_challenge is None:
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:
return redirect(url_for('frontend.index'))
@ -160,7 +160,7 @@ def login_auth() -> ResponseReturnValue:
subject = user.id
user.last_login = datetime.now()
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(
subject=subject,
remember=remember_me,
@ -172,12 +172,12 @@ def login_auth() -> ResponseReturnValue:
@auth_views.route("/logout")
def logout() -> ResponseReturnValue:
async def logout() -> ResponseReturnValue:
logout_challenge = request.args.get('logout_challenge')
if logout_challenge is None:
return 'invalid request, logout_challenge not set', 400
# 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):
return 'internal error, could not forward request', 503
return redirect(resp.redirect_to)