2020-08-27 14:08:26 +00:00
|
|
|
import json
|
2021-12-20 22:57:27 +00:00
|
|
|
|
|
|
|
from flask import Blueprint
|
|
|
|
from flask import current_app
|
2022-10-03 15:25:32 +00:00
|
|
|
from flask import g
|
2021-12-20 22:57:27 +00:00
|
|
|
from flask import jsonify
|
2022-10-03 15:25:32 +00:00
|
|
|
from flask import request
|
2020-08-27 14:08:26 +00:00
|
|
|
|
|
|
|
|
2022-01-11 18:49:06 +00:00
|
|
|
bp = Blueprint("home", __name__, url_prefix="/.well-known")
|
2020-08-27 14:08:26 +00:00
|
|
|
|
|
|
|
|
2022-10-03 15:25:32 +00:00
|
|
|
def cached_oauth_authorization_server():
|
|
|
|
if "oauth_authorization_server" not in g:
|
|
|
|
with open(current_app.config["OAUTH2_METADATA_FILE"]) as fd:
|
|
|
|
g.oauth_authorization_server = json.load(fd)
|
|
|
|
return g.oauth_authorization_server
|
|
|
|
|
|
|
|
|
|
|
|
def cached_openid_configuration():
|
|
|
|
if "openid_configuration" not in g:
|
|
|
|
with open(current_app.config["OIDC_METADATA_FILE"]) as fd:
|
|
|
|
g.openid_configuration = json.load(fd)
|
|
|
|
return g.openid_configuration
|
|
|
|
|
|
|
|
|
2020-08-27 14:08:26 +00:00
|
|
|
@bp.route("/oauth-authorization-server")
|
|
|
|
def oauth_authorization_server():
|
2022-10-03 17:32:39 +00:00
|
|
|
return jsonify(cached_oauth_authorization_server())
|
2020-08-27 14:08:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/openid-configuration")
|
|
|
|
def openid_configuration():
|
2022-10-03 17:32:39 +00:00
|
|
|
return jsonify(cached_openid_configuration())
|
2022-10-03 15:25:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/webfinger")
|
|
|
|
def webfinger():
|
|
|
|
return jsonify(
|
|
|
|
{
|
|
|
|
"links": [
|
|
|
|
{
|
|
|
|
"href": cached_openid_configuration()["issuer"],
|
|
|
|
"rel": "http://openid.net/specs/connect/1.0/issuer",
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"subject": request.args["resource"],
|
|
|
|
}
|
|
|
|
)
|