Skip to content
Snippets Groups Projects

feat: extend consent management api

Merged Peter Bolha requested to merge extend_consent_api into main
Files
2
@@ -4,7 +4,6 @@ from urllib.parse import urlencode
import requests
from flask import Blueprint, redirect, session, url_for, request, flash, abort, jsonify
from flask_login import current_user
def configure_oauth_info(cfg):
@@ -24,9 +23,6 @@ def construct_oauth_api(cfg):
@oauth_api.route("/authorize")
def oauth2_authorize():
if not current_user.is_anonymous:
# TODO redirect somewhere or handle situation when user is already logged in
return redirect(url_for("index"))
# generate a random string for the state parameter
session["oauth2_state"] = secrets.token_urlsafe(16)
@@ -50,14 +46,10 @@ def construct_oauth_api(cfg):
@oauth_api.route("/callback")
def oauth2_callback():
if not current_user.is_anonymous:
# TODO redirect somewhere or handle situation when user is already logged
# in, same as /authorize endpoint
return redirect(url_for("index"))
provider_data = cfg["consent"]["oauth2_provider"]
# if there was an authentication error, flash the error messages and exit
# if there was an authentication error, flash the error messages and
# exit
if "error" in request.args:
for k, v in request.args.items():
if k.startswith("error"):
@@ -68,7 +60,9 @@ def construct_oauth_api(cfg):
# make sure that the state parameter matches the one we created in the
# authorization request
if request.args["state"] != session.get("oauth2_state"):
abort(401, "State in the request does not match the state in the session.")
abort(
401, "State in the request does not match the state in the " "session."
)
# make sure that the authorization code is present
if "code" not in request.args:
Loading