zamzterz/Flask-pyoidc

Cannot build url for 'logout' when using dynamic client registration

Closed this issue · 0 comments

If the logout view is mounted under a custom endpoint (other than the default, which is the name of the view function), or if using Blueprints, you must specify the full URL in the Flask-pyoidc configuration using post_logout_redirect_uris.

This is working as intended but when using dynamic client registration these methods are called:

def _register_client(self, client):

post_logout_redirect_uris = client._provider_configuration._client_registration_info.get(
'post_logout_redirect_uris',
default_post_logout_redirect_uris())

url_for_logout_view = self._get_url_for_logout_view()

def _get_url_for_logout_view(self):
return url_for(self._logout_view.__name__, _external=True) if self._logout_view else None

self._logout_view.__name__ returns the name of the view function. url_for uses the route registration to find the route registered against that name. If the view function is mounted at blueprint, its name is prefixed by the name of the blueprint so providing only __name__ to url_for is not enough.

blueprint = Blueprint('api', __name__, url_prefix='/api/v1')
@blueprint.route('/logout')
def logout():

    return 'You have been logged out'

print(url_for('api.logout'))
# http://localhost:5000/api/v1/logout
print(url_for('logout'))
# Cannot build url for 'logout'. Did you mean 'api.logout'?

.get() will always call that method to set default value even if post_logout_redirect_uris is provided as an argument.