codecov-io: # [Codecov](https://codecov.io/gh/zamzterz/Flask-pyoidc/pull/57?src=pr&el=h1) Report
> Merging [#57](https://codecov.io/gh/zamzterz/Flask-pyoidc/pull/57?src=pr&el=desc) into [master](https://codecov.io/gh/zamzterz/Flask-pyoidc/commit/c1494d755af1d427bc214446699eb97f951eb09d?src=pr&el=desc) will **increase** coverage by `0.03%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/zamzterz/Flask-pyoidc/pull/57/graphs/tree.svg?width=650&token=xbSknAkssg&height=150&src=pr)](https://codecov.io/gh/zamzterz/Flask-pyoidc/pull/57?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master      #57      +/-   ##
==========================================
+ Coverage   96.81%   96.84%   +0.03%     
==========================================
  Files           7        7              
  Lines         471      476       +5     
  Branches       54       56       +2     
==========================================
+ Hits          456      461       +5     
  Misses          8        8              
  Partials        7        7
```


| [Impacted Files](https://codecov.io/gh/zamzterz/Flask-pyoidc/pull/57?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/flask\_pyoidc/flask\_pyoidc.py](https://codecov.io/gh/zamzterz/Flask-pyoidc/pull/57/diff?src=pr&el=tree#diff-c3JjL2ZsYXNrX3B5b2lkYy9mbGFza19weW9pZGMucHk=) | `91.6% <100%> (+0.3%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/zamzterz/Flask-pyoidc/pull/57?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/zamzterz/Flask-pyoidc/pull/57?src=pr&el=footer). Last update [c1494d7...284f565](https://codecov.io/gh/zamzterz/Flask-pyoidc/pull/57?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

diff --git a/README.md b/README.md
index adb7848..39601ae 100644
--- a/README.md
+++ b/README.md
@@ -66,6 +66,8 @@ config = ProviderConfiguration([provider configuration], client_metadata=client_
 
 **Note: The redirect URIs registered with the provider MUST include `<application_url>/redirect_uri`,
 where `<application_url>` is the URL of the Flask application.**
+To configure this extension to use a different endpoint, set the
+[`OIDC_REDIRECT_ENDPOINT` configuration parameter](#flask-configuration).
 
 #### Dynamic client registration
 
@@ -91,6 +93,8 @@ You may also configure the way the user sessions created by this extension are h
 
 * `OIDC_SESSION_PERMANENT`: If set to `True` (which is the default) the user session will be kept until the configured
   session lifetime (see below). If set to `False` the session will be deleted when the user closes the browser.
+* `OIDC_REDIRECT_ENDPOINT`: Set the endpoint used as redirect_uri to receive authentication responses. Defaults to
+  `redirect_uri`, meaning the URL `<application_url>/redirect_uri` needs to be registered with the provider(s).
 * `PERMANENT_SESSION_LIFETIME`: Control how long a user session is valid, see
   [Flask documentation](http://flask.pocoo.org/docs/1.0/config/#PERMANENT_SESSION_LIFETIME) for more information.
 
diff --git a/src/flask_pyoidc/flask_pyoidc.py b/src/flask_pyoidc/flask_pyoidc.py
index 79816d2..132ddc6 100644
--- a/src/flask_pyoidc/flask_pyoidc.py
+++ b/src/flask_pyoidc/flask_pyoidc.py
@@ -36,13 +36,12 @@ try:
 except ImportError:
     from urlparse import parse_qsl
 
+
 class OIDCAuthentication(object):
     """
     OIDCAuthentication object for Flask extension.
     """
 
-    REDIRECT_URI_ENDPOINT = 'redirect_uri'
-
     def __init__(self, provider_configurations, app=None):
         """
         Args:
@@ -55,21 +54,24 @@ class OIDCAuthentication(object):
         self.clients = None
         self._logout_view = None
         self._error_view = None
+        self._redirect_uri_endpoint = None
 
         if app:
             self.init_app(app)
 
     def init_app(self, app):
+        self._redirect_uri_endpoint = app.config.get('OIDC_REDIRECT_ENDPOINT', 'redirect_uri').lstrip('/')
+
         # setup redirect_uri as a flask route
-        app.add_url_rule('/redirect_uri',
-                         self.REDIRECT_URI_ENDPOINT,
+        app.add_url_rule('/' + self._redirect_uri_endpoint,
+                         self._redirect_uri_endpoint,
                          self._handle_authentication_response,
                          methods=['GET', 'POST'])
 
         # dynamically add the Flask redirect uri to the client info
         with app.app_context():
             self.clients = {
-                name: PyoidcFacade(configuration, url_for(self.REDIRECT_URI_ENDPOINT))
+                name: PyoidcFacade(configuration, url_for(self._redirect_uri_endpoint))
                 for (name, configuration) in self._provider_configurations.items()
             }
 
@@ -161,7 +163,7 @@ class OIDCAuthentication(object):
             # if the current request was from the JS page handling fragment encoded responses we need to return
             # a URL for the error page to redirect to
             flask.session['error'] = error_response
-            return '/redirect_uri?error=1'
+            return '/' + self._redirect_uri_endpoint + '?error=1'
         return self._show_error_response(error_response)
 
     def _show_error_response(self, error_response):

Do not hardcode routes like `/redirect_uri`
Better provide a default which people can then override.
diff --git a/tests/test_flask_pyoidc.py b/tests/test_flask_pyoidc.py
index 78cde1a..a2eca3a 100644
--- a/tests/test_flask_pyoidc.py
+++ b/tests/test_flask_pyoidc.py
@@ -468,3 +468,9 @@ class TestOIDCAuthentication(object):
         with pytest.raises(ValueError) as exc_info:
             self.init_app().oidc_auth('unknown')
         assert 'unknown' in str(exc_info.value)
+
+    def test_should_use_custom_redirect_endpoint(self):
+        self.app.config['OIDC_REDIRECT_ENDPOINT'] = '/openid_connect_login'
+        authn = self.init_app()
+        assert authn._redirect_uri_endpoint == 'openid_connect_login'
+        assert authn.clients['test_provider']._redirect_uri == 'http://client.example.com/openid_connect_login'

pip install -e .
parse_log_pytest
requirements.txt
pytest
apt-get update apt-get install -y gcc
3.6
tests/requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
alabaster==0.7.13
attrs==22.2.0
Beaker==1.13.0
certifi==2021.5.30
cffi==1.15.1
charset-normalizer==2.0.12
click==8.0.4
cryptography==40.0.2
dataclasses==0.8
Flask==2.0.3
-e git+https://github.com/zamzterz/Flask-pyoidc.git@c1494d755af1d427bc214446699eb97f951eb09d#egg=Flask_pyoidc
future==1.0.0
idna==3.10
importlib-metadata==4.8.3
iniconfig==1.1.1
itsdangerous==2.0.1
Jinja2==3.0.3
Mako==1.1.6
MarkupSafe==2.0.1
mock==5.2.0
oic==0.12.0
packaging==21.3
pluggy==1.0.0
py==1.11.0
pycparser==2.21
pycryptodomex==3.21.0
pyjwkest==1.4.2
pyOpenSSL==23.2.0
pyparsing==3.1.4
pytest==7.0.1
requests==2.27.1
responses==0.17.0
six==1.17.0
tomli==1.2.3
typing_extensions==4.1.1
urllib3==1.26.20
Werkzeug==2.0.3
zipp==3.6.0

name: Flask-pyoidc
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=21.2.2=py36h06a4308_0
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - alabaster==0.7.13
      - attrs==22.2.0
      - beaker==1.13.0
      - cffi==1.15.1
      - charset-normalizer==2.0.12
      - click==8.0.4
      - cryptography==40.0.2
      - dataclasses==0.8
      - flask==2.0.3
      - future==1.0.0
      - idna==3.10
      - importlib-metadata==4.8.3
      - iniconfig==1.1.1
      - itsdangerous==2.0.1
      - jinja2==3.0.3
      - mako==1.1.6
      - markupsafe==2.0.1
      - mock==5.2.0
      - oic==0.12.0
      - packaging==21.3
      - pluggy==1.0.0
      - py==1.11.0
      - pycparser==2.21
      - pycryptodomex==3.21.0
      - pyjwkest==1.4.2
      - pyopenssl==23.2.0
      - pyparsing==3.1.4
      - pytest==7.0.1
      - requests==2.27.1
      - responses==0.17.0
      - six==1.17.0
      - tomli==1.2.3
      - typing-extensions==4.1.1
      - urllib3==1.26.20
      - werkzeug==2.0.3
      - zipp==3.6.0
prefix: /opt/conda/envs/Flask-pyoidc

tests/test_flask_pyoidc.py::TestOIDCAuthentication::test_should_use_custom_redirect_endpoint
tests/test_flask_pyoidc.py::TestOIDCAuthentication::test_session_expiration_set_to_configured_lifetime
tests/test_flask_pyoidc.py::TestOIDCAuthentication::test_should_authenticate_if_no_session tests/test_flask_pyoidc.py::TestOIDCAuthentication::test_should_not_authenticate_if_session_exists tests/test_flask_pyoidc.py::TestOIDCAuthentication::test_reauthenticate_silent_if_session_expired tests/test_flask_pyoidc.py::TestOIDCAuthentication::test_dont_reauthenticate_silent_if_session_not_expired tests/test_flask_pyoidc.py::TestOIDCAuthentication::test_expected_auth_response_mode_is_set[code-False] tests/test_flask_pyoidc.py::TestOIDCAuthentication::test_expected_auth_response_mode_is_set[id_token tests/test_flask_pyoidc.py::TestOIDCAuthentication::test_should_register_client_if_not_registered_before tests/test_flask_pyoidc.py::TestOIDCAuthentication::test_handle_authentication_response tests/test_flask_pyoidc.py::TestOIDCAuthentication::test_handle_implicit_authentication_response tests/test_flask_pyoidc.py::TestOIDCAuthentication::test_handle_authentication_response_POST tests/test_flask_pyoidc.py::TestOIDCAuthentication::test_handle_authentication_response_fragment_encoded tests/test_flask_pyoidc.py::TestOIDCAuthentication::test_handle_authentication_response_error_message tests/test_flask_pyoidc.py::TestOIDCAuthentication::test_handle_authentication_response_error_message_without_stored_error tests/test_flask_pyoidc.py::TestOIDCAuthentication::test_logout_redirects_to_provider_if_end_session_endpoint_is_configured tests/test_flask_pyoidc.py::TestOIDCAuthentication::test_logout_handles_provider_without_end_session_endpoint tests/test_flask_pyoidc.py::TestOIDCAuthentication::test_logout_handles_redirect_back_from_provider tests/test_flask_pyoidc.py::TestOIDCAuthentication::test_logout_handles_redirect_back_from_provider_with_incorrect_state tests/test_flask_pyoidc.py::TestOIDCAuthentication::test_authentication_error_response_calls_to_error_view_if_set tests/test_flask_pyoidc.py::TestOIDCAuthentication::test_authentication_error_response_returns_default_error_if_no_error_view_set tests/test_flask_pyoidc.py::TestOIDCAuthentication::test_token_error_response_calls_to_error_view_if_set tests/test_flask_pyoidc.py::TestOIDCAuthentication::test_token_error_response_returns_default_error_if_no_error_view_set tests/test_flask_pyoidc.py::TestOIDCAuthentication::test_using_unknown_provider_name_should_raise_exception
src/flask_pyoidc/flask_pyoidc.py README.md
src/flask_pyoidc/flask_pyoidc.py README.md