File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change 22
33State is useful if you want the server to return something back to you to help you understand in what
44context the authentication was initiated. It is mostly used to store the url you want your user to be redirected
5- to after successful login. You may use ` .state ` property to get the state returned from the server.
5+ to after successful login. You may use ` .state ` property to get the state returned from the server or access
6+ it from the ` state ` parameter in the callback function.
67
78Example:
89
@@ -19,9 +20,11 @@ async def google_login(return_url: str):
1920 # Send return_url to Google as a state so that Google knows to return it back to us
2021 return await google_sso.get_login_redirect(redirect_uri = request.url_for(" google_callback" ), state = return_url)
2122
22- async def google_callback (request : Request):
23+ async def google_callback (request : Request, state : str | None = None ):
2324 async with google_sso:
2425 user = await google_sso.verify_and_process(request)
25- # google_sso.state now holds your return_url (https://example.com/welcome)
26- return RedirectResponse(google_sso.state)
26+ if state is not None :
27+ return RedirectResponse(state)
28+ else :
29+ return user
2730```
You can’t perform that action at this time.
0 commit comments