From 88eae5f263bc816384fd124f06a28633ee8180ce Mon Sep 17 00:00:00 2001 From: Alexander_Kabui Date: Wed, 18 Sep 2024 16:09:48 +0300 Subject: Refactor: try to build endpoint with get request. If BuildError is raised default to "/" --- gn2/wqflask/oauth2/checks.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'gn2/wqflask/oauth2') diff --git a/gn2/wqflask/oauth2/checks.py b/gn2/wqflask/oauth2/checks.py index 55338930..8a6e439e 100644 --- a/gn2/wqflask/oauth2/checks.py +++ b/gn2/wqflask/oauth2/checks.py @@ -4,6 +4,7 @@ from urllib.parse import urljoin from flask import flash, request, redirect, url_for from authlib.integrations.requests_client import OAuth2Session +from werkzeug.routing import BuildError from . import session from .client import ( @@ -30,9 +31,9 @@ def require_oauth2(func): Save the current user request to session then redirect to the login page. """ - if request.method == "GET": - redirect_url = url_for(request.endpoint, **request.args) - else: + try: + redirect_url = url_for(request.endpoint, _method="GET", **request.args) + except BuildError: redirect_url = "/" session.set_redirect_url(redirect_url) return redirect(authserver_authorise_uri()) -- cgit v1.2.3