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

Authlib 1.2.0 redirect_uri returns URL object instead of string #535

Closed
rmblau opened this issue Mar 28, 2023 · 5 comments
Closed

Authlib 1.2.0 redirect_uri returns URL object instead of string #535

rmblau opened this issue Mar 28, 2023 · 5 comments
Assignees
Labels

Comments

@rmblau
Copy link

rmblau commented Mar 28, 2023

Describe the bug

In 1.1.0 the redirect uri was a string, in 1.2.0 the same code breaks because the redirect_uri is a URL object. The docs do not mention this change nor can I locate documentation on how to utilize this object.

Error Stacks

starbudget            |     return await google.authorize_redirect(request, redirect_uri)
starbudget            |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
starbudget            |   File "/usr/local/lib/python3.11/site-packages/authlib/integrations/starlette_client/apps.py", line 29, in authorize_redirect
starbudget            |     rv = await self.create_authorization_url(redirect_uri, **kwargs)
starbudget            |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
starbudget            |   File "/usr/local/lib/python3.11/site-packages/authlib/integrations/base_client/async_app.py", line 105, in create_authorization_url
starbudget            |     return self._create_oauth2_authorization_url(
starbudget            |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
starbudget            |   File "/usr/local/lib/python3.11/site-packages/authlib/integrations/base_client/sync_app.py", line 265, in _create_oauth2_authorization_url
starbudget            |     url, state = client.create_authorization_url(
starbudget            |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
starbudget            |   File "/usr/local/lib/python3.11/site-packages/authlib/oauth2/client.py", line 153, in create_authorization_url
starbudget            |     uri = prepare_grant_uri(
starbudget            |           ^^^^^^^^^^^^^^^^^^
starbudget            |   File "/usr/local/lib/python3.11/site-packages/authlib/oauth2/rfc6749/parameters.py", line 66, in prepare_grant_uri
starbudget            |     return add_params_to_uri(uri, params)
starbudget            |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
starbudget            |   File "/usr/local/lib/python3.11/site-packages/authlib/common/urls.py", line 99, in add_params_to_uri
starbudget            |     query = add_params_to_qs(query, params)
starbudget            |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
starbudget            |   File "/usr/local/lib/python3.11/site-packages/authlib/common/urls.py", line 90, in add_params_to_qs
starbudget            |     return url_encode(qs)
starbudget            |            ^^^^^^^^^^^^^^
starbudget            |   File "/usr/local/lib/python3.11/site-packages/authlib/common/urls.py", line 28, in url_encode
starbudget            |     encoded.append((to_bytes(k), to_bytes(v)))
starbudget            |                                  ^^^^^^^^^^^
starbudget            |   File "/usr/local/lib/python3.11/site-packages/authlib/common/encoding.py", line 15, in to_bytes
starbudget            |     return bytes(x)
starbudget            |            ^^^^^^^^
starbudget            | TypeError: cannot convert 'URL' object to bytes

put error stacks here


**To Reproduce**

To reproduce, follow this https://docs.authlib.org/en/latest/client/starlette.html#routes-for-authorization. The code example no longer works.

**Expected behavior**

I expect it to behave like it did in 1.1.0 and redirect properly.

**Environment:**

 - OS: debian 11
 - Python Version: 3.11
 - Authlib Version: 1.2.0

**Additional context**

Add any other context about the problem here.
@rmblau
Copy link
Author

rmblau commented Mar 28, 2023

Just noticed this is in fact a starlette bug, closing issue

@rmblau rmblau closed this as completed Mar 28, 2023
@aartaviab
Copy link

do you have the github link of that Starlette bug? thanks

@nurettn
Copy link

nurettn commented Apr 2, 2023

@rmblau This PR seems not enough to resolve this error: #533

@Jsalaz1989
Copy link

In my case wrapping the oauth.google.authorize_redirect() with str does the trick:

@app.get("/login/google")
async def login_via_google(request: Request):
    redirect_uri = request.url_for('auth_via_google')
    return await oauth.google.authorize_redirect(request, str(redirect_uri)) # wrap with str()

@alvartabe
Copy link

In my case wrapping the oauth.google.authorize_redirect() with str does the trick:

@app.get("/login/google")
async def login_via_google(request: Request):
    redirect_uri = request.url_for('auth_via_google')
    return await oauth.google.authorize_redirect(request, str(redirect_uri)) # wrap with str()

hey! thanks for this workaround, its also working for me!

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

No branches or pull requests

6 participants