diff --git a/invenio_oauthclient/ext.py b/invenio_oauthclient/ext.py index 77c7d00..8c54dca 100644 --- a/invenio_oauthclient/ext.py +++ b/invenio_oauthclient/ext.py @@ -169,7 +169,6 @@ def __init__(self, app=None): def init_app(self, app): """Flask application initialization.""" - self.init_config(app) state = _OAuthClientState( app, "OAUTHCLIENT_REMOTE_APPS", @@ -179,24 +178,6 @@ def init_app(self, app): app.extensions["invenio-oauthclient"] = state return state - def init_config(self, app): - """Initialize configuration.""" - - @app.before_first_request - def override_template_configuration(): - """Override template configuration.""" - template_key = app.config.get( - "OAUTHCLIENT_TEMPLATE_KEY", - "SECURITY_LOGIN_USER_TEMPLATE", # default template key - ) - if template_key is not None: - template = app.config[template_key] # keep the old value - app.config["OAUTHCLIENT_LOGIN_USER_TEMPLATE_PARENT"] = template - app.config[template_key] = app.config.get( - "OAUTHCLIENT_LOGIN_USER_TEMPLATE", - "invenio_oauthclient/login_user.html", - ) - class InvenioOAuthClientREST(object): """Invenio Oauthclient extension.""" diff --git a/invenio_oauthclient/finalize_app.py b/invenio_oauthclient/finalize_app.py new file mode 100644 index 0000000..e3d3c34 --- /dev/null +++ b/invenio_oauthclient/finalize_app.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# +# This file is part of Invenio. +# Copyright (C) 2023 Graz University of Technology. +# +# Invenio is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""Finalize app.""" + + +def finalize_app(app): + """Finalize app.""" + + override_template_configuration(app) + + +def override_template_configuration(app): + """Override template configuration.""" + template_key = app.config.get( + "OAUTHCLIENT_TEMPLATE_KEY", + "SECURITY_LOGIN_USER_TEMPLATE", # default template key + ) + if template_key is not None: + template = app.config[template_key] # keep the old value + app.config["OAUTHCLIENT_LOGIN_USER_TEMPLATE_PARENT"] = template + app.config[template_key] = app.config.get( + "OAUTHCLIENT_LOGIN_USER_TEMPLATE", + "invenio_oauthclient/login_user.html", + ) diff --git a/setup.cfg b/setup.cfg index edc5ec3..e9759d1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -85,6 +85,8 @@ invenio_base.secret_key = invenio_oauthclient = invenio_oauthclient.utils:rebuild_access_tokens invenio_i18n.translations = invenio_oauthclient = invenio_oauthclient +invenio_base.finalize_app = + invenio_oauthclient = invenio_oauthclient.finalize_app:finalize_app [build_sphinx] source-dir = docs/