Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception while trying to redirect to login in test environment #93

Open
mvalik opened this issue Jul 11, 2024 · 1 comment
Open

Exception while trying to redirect to login in test environment #93

mvalik opened this issue Jul 11, 2024 · 1 comment

Comments

@mvalik
Copy link

mvalik commented Jul 11, 2024

When I'm trying to create a test which is calling to the endpoint with the decorator @flask_oidc.require_login I got the following exception:

>       r = client.get(url, follow_redirects=False)

test_auth.py:110: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../../../.cache/pypoetry/virtualenvs/waiverdb-jda4S8Iw-py3.12/lib/python3.12/site-packages/werkzeug/test.py:1162: in get
    return self.open(*args, **kw)
../../../.cache/pypoetry/virtualenvs/waiverdb-jda4S8Iw-py3.12/lib/python3.12/site-packages/flask/testing.py:238: in open
    response = super().open(
../../../.cache/pypoetry/virtualenvs/waiverdb-jda4S8Iw-py3.12/lib/python3.12/site-packages/werkzeug/test.py:1116: in open
    response_parts = self.run_wsgi_app(request.environ, buffered=buffered)
../../../.cache/pypoetry/virtualenvs/waiverdb-jda4S8Iw-py3.12/lib/python3.12/site-packages/werkzeug/test.py:988: in run_wsgi_app
    rv = run_wsgi_app(self.application, environ, buffered=buffered)
../../../.cache/pypoetry/virtualenvs/waiverdb-jda4S8Iw-py3.12/lib/python3.12/site-packages/werkzeug/test.py:1264: in run_wsgi_app
    app_rv = app(environ, start_response)
../../../.cache/pypoetry/virtualenvs/waiverdb-jda4S8Iw-py3.12/lib/python3.12/site-packages/flask/app.py:2552: in __call__
    return self.wsgi_app(environ, start_response)
../../../.cache/pypoetry/virtualenvs/waiverdb-jda4S8Iw-py3.12/lib/python3.12/site-packages/flask/app.py:2532: in wsgi_app
    response = self.handle_exception(e)
../../../.cache/pypoetry/virtualenvs/waiverdb-jda4S8Iw-py3.12/lib/python3.12/site-packages/flask_cors/extension.py:178: in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
../../../.cache/pypoetry/virtualenvs/waiverdb-jda4S8Iw-py3.12/lib/python3.12/site-packages/flask_restx/api.py:671: in error_router
    return original_handler(f)
../../../.cache/pypoetry/virtualenvs/waiverdb-jda4S8Iw-py3.12/lib/python3.12/site-packages/flask_restx/api.py:669: in error_router
    return self.handle_error(e)
../../../.cache/pypoetry/virtualenvs/waiverdb-jda4S8Iw-py3.12/lib/python3.12/site-packages/flask/app.py:2529: in wsgi_app
    response = self.full_dispatch_request()
../../../.cache/pypoetry/virtualenvs/waiverdb-jda4S8Iw-py3.12/lib/python3.12/site-packages/flask/app.py:1825: in full_dispatch_request
    rv = self.handle_user_exception(e)
../../../.cache/pypoetry/virtualenvs/waiverdb-jda4S8Iw-py3.12/lib/python3.12/site-packages/flask_cors/extension.py:178: in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
../../../.cache/pypoetry/virtualenvs/waiverdb-jda4S8Iw-py3.12/lib/python3.12/site-packages/flask_restx/api.py:671: in error_router
    return original_handler(f)
../../../.cache/pypoetry/virtualenvs/waiverdb-jda4S8Iw-py3.12/lib/python3.12/site-packages/flask_restx/api.py:669: in error_router
    return self.handle_error(e)
../../../.cache/pypoetry/virtualenvs/waiverdb-jda4S8Iw-py3.12/lib/python3.12/site-packages/flask/app.py:1823: in full_dispatch_request
    rv = self.dispatch_request()
../../../.cache/pypoetry/virtualenvs/waiverdb-jda4S8Iw-py3.12/lib/python3.12/site-packages/flask/app.py:1799: in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
../../../.cache/pypoetry/virtualenvs/waiverdb-jda4S8Iw-py3.12/lib/python3.12/site-packages/flask_restx/api.py:402: in wrapper
    resp = resource(*args, **kwargs)
../../../.cache/pypoetry/virtualenvs/waiverdb-jda4S8Iw-py3.12/lib/python3.12/site-packages/flask/views.py:107: in view
    return current_app.ensure_sync(self.dispatch_request)(**kwargs)
../../../.cache/pypoetry/virtualenvs/waiverdb-jda4S8Iw-py3.12/lib/python3.12/site-packages/flask_restx/resource.py:41: in dispatch_request
    resp = meth(*args, **kwargs)
../../../.cache/pypoetry/virtualenvs/waiverdb-jda4S8Iw-py3.12/lib/python3.12/site-packages/flask_oidc/__init__.py:311: in decorated
    login=url_for("oidc_auth.login"),
../../../.cache/pypoetry/virtualenvs/waiverdb-jda4S8Iw-py3.12/lib/python3.12/site-packages/flask/helpers.py:256: in url_for
    return current_app.url_for(
../../../.cache/pypoetry/virtualenvs/waiverdb-jda4S8Iw-py3.12/lib/python3.12/site-packages/flask/app.py:2034: in url_for
    return self.handle_url_build_error(error, endpoint, values)
../../../.cache/pypoetry/virtualenvs/waiverdb-jda4S8Iw-py3.12/lib/python3.12/site-packages/flask/app.py:2023: in url_for
    rv = url_adapter.build(  # type: ignore[union-attr]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <werkzeug.routing.map.MapAdapter object at 0x7f5a93399790>
endpoint = 'oidc_auth.login', values = {}, method = None, force_external = False
append_unknown = True, url_scheme = None

    def build(
        self,
        endpoint: t.Any,

... werkzeug code skipped for better readability ...

       
        rv = self._partial_build(endpoint, values, method, append_unknown)
        if rv is None:
>           raise BuildError(endpoint, values, method, self)
E           werkzeug.routing.exceptions.BuildError: Could not build url for endpoint 'oidc_auth.login'. Did you mean 'login' instead?

../../../.cache/pypoetry/virtualenvs/waiverdb-jda4S8Iw-py3.12/lib/python3.12/site-packages/werkzeug/routing/map.py:924: BuildError

In my local environment, I've replaced: url_for("oidc_auth.login"), to url_for("login"), directly in library and that's worked for me.

@abompard
Copy link
Member

Hi! That's surprising, flask-oidc provides a blueprint named oidc_auth and registers it with the app when the extension is instantiated (or when init_app() is called). How is the OpenIDConnect object instantiated? Which version of flask-oidc are you using? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants