Skip to content

Commit c428b85

Browse files
committedNov 29, 2024·
allow extra state to be persisted between login and callback - for example to store a 'return to' url to redirect the user to after they login
1 parent 639ca66 commit c428b85

File tree

1 file changed

+5
-1
lines changed
  • authlib/integrations/starlette_client

1 file changed

+5
-1
lines changed
 

‎authlib/integrations/starlette_client/apps.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ async def save_authorize_data(self, request, **kwargs):
1919
else:
2020
raise RuntimeError('Missing state value')
2121

22-
async def authorize_redirect(self, request, redirect_uri=None, **kwargs):
22+
async def authorize_redirect(self, request, redirect_uri=None, extra_state=None, **kwargs):
2323
"""Create a HTTP Redirect for Authorization Endpoint.
2424
2525
:param request: HTTP request instance from Starlette view.
2626
:param redirect_uri: Callback or redirect URI for authorization.
27+
:param extra_state: Extra state data to be stored in session.
2728
:param kwargs: Extra parameters to include.
2829
:return: A HTTP redirect response.
2930
"""
@@ -32,6 +33,7 @@ async def authorize_redirect(self, request, redirect_uri=None, **kwargs):
3233
if redirect_uri and isinstance(redirect_uri, URL):
3334
redirect_uri = str(redirect_uri)
3435
rv = await self.create_authorization_url(redirect_uri, **kwargs)
36+
rv['extra_state'] = extra_state
3537
await self.save_authorize_data(request, redirect_uri=redirect_uri, **rv)
3638
return RedirectResponse(rv['url'], status_code=302)
3739

@@ -83,4 +85,6 @@ async def authorize_access_token(self, request, **kwargs):
8385
if 'id_token' in token and 'nonce' in state_data:
8486
userinfo = await self.parse_id_token(token, nonce=state_data['nonce'], claims_options=claims_options)
8587
token['userinfo'] = userinfo
88+
if 'extra_state' in state_data:
89+
token['extra_state'] = state_data['extra_state']
8690
return token

0 commit comments

Comments
 (0)