Skip to content

Commit b240d0d

Browse files
authored
docs: update guide on return urls (#206)
1 parent 0232a3e commit b240d0d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

docs/how-to-guides/state-return-url.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
State is useful if you want the server to return something back to you to help you understand in what
44
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.
67

78
Example:
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
```

0 commit comments

Comments
 (0)