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

redirect_uri str type expected (type=type_error.str) #23

Closed
gchait opened this issue Jun 2, 2023 · 2 comments
Closed

redirect_uri str type expected (type=type_error.str) #23

gchait opened this issue Jun 2, 2023 · 2 comments

Comments

@gchait
Copy link

gchait commented Jun 2, 2023

Thank you for this package!
I tried setting up FastAPI with AzureAD for days, and used many packages.
But only using this package, combined with starlette-authlib (encode/starlette#2019 (comment)) resulted in the expected behavior.

However, as it is, I am encountering a crash with this traceback:

  File "/py/lib/python3.11/site-packages/fastapi_msal/auth.py", line 66, in _login_route
    return await self.handler.authorize_redirect(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/py/lib/python3.11/site-packages/fastapi_msal/security/msal_auth_code_handler.py", line 26, in authorize_redirect
    auth_code: AuthCode = await self.msal_app().initiate_auth_flow(
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/py/lib/python3.11/site-packages/fastapi_msal/clients/async_conf_client.py", line 95, in initiate_auth_flow
    return AuthCode.parse_obj_debug(to_parse=auth_code)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/py/lib/python3.11/site-packages/fastapi_msal/models/base_auth_model.py", line 13, in parse_obj_debug
    debug_model: AuthModel = cls.parse_obj(obj=to_parse)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "pydantic/main.py", line 526, in pydantic.main.BaseModel.parse_obj
  File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for AuthCode
redirect_uri
  str type expected (type=type_error.str)

So as a workaround, I put this line in my Dockerfile and now it works:

RUN sed -i "s/redirec_uri=redirect_uri/redirec_uri=str(redirect_uri)/" /py/lib/python3.11/site-packages/fastapi_msal/auth.py

BTW: In some places over there, it says redirec instead of redirect.
Thanks again.

@reastyn
Copy link
Contributor

reastyn commented Sep 29, 2023

Hey, I came across the same error and created a fix for it. It is backwards compatible and only a small change in the code. Can you please check it @dudil? Thanks a lot for your work!

@dudil
Copy link
Owner

dudil commented Oct 3, 2023

Hi @reastyn - I've update the package on PyPi it is version 1.8.1
I Had to add other changes since I was also changing the publish scripts and the backend to Hatch.
So please make sure you are checking that through - this release might not work since all the base packages had change since then.

@dudil dudil closed this as completed Dec 4, 2023
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

3 participants