File tree 1 file changed +7
-4
lines changed
1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change 2
2
3
3
State is useful if you want the server to return something back to you to help you understand in what
4
4
context 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.
6
7
7
8
Example:
8
9
@@ -19,9 +20,11 @@ async def google_login(return_url: str):
19
20
# Send return_url to Google as a state so that Google knows to return it back to us
20
21
return await google_sso.get_login_redirect(redirect_uri = request.url_for(" google_callback" ), state = return_url)
21
22
22
- async def google_callback (request : Request):
23
+ async def google_callback (request : Request, state : str | None = None ):
23
24
async with google_sso:
24
25
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
27
30
```
You can’t perform that action at this time.
0 commit comments