|
1 | | -from typing import Optional |
| 1 | +from typing import Optional, Annotated |
2 | 2 |
|
3 | 3 | from fastapi import APIRouter, Depends, HTTPException, Query, Request, Response |
4 | 4 | from fastapi.responses import RedirectResponse |
@@ -93,7 +93,7 @@ async def callback( |
93 | 93 | # Assuming config is stored on app.state |
94 | 94 | default_redirect = auth_client.config.app_base_url |
95 | 95 |
|
96 | | - safe_redirect = to_safe_redirect(return_to or default_redirect, auth_client.config.app_base_url) |
| 96 | + safe_redirect = to_safe_redirect(return_to, default_redirect) if return_to else str(default_redirect) |
97 | 97 | return RedirectResponse(url=safe_redirect, headers=response.headers) |
98 | 98 |
|
99 | 99 | @router.get("/auth/logout") |
@@ -147,18 +147,20 @@ async def connect_account( |
147 | 147 | request: Request, |
148 | 148 | response: Response, |
149 | 149 | connection: str = Query(), |
| 150 | + scopes: Annotated[list[str] | None, Query()] = None, |
| 151 | + return_to: str = Query(default=None), |
150 | 152 | auth_client: AuthClient = Depends(get_auth_client), |
151 | 153 | ): |
152 | 154 | """ |
153 | 155 | Endpoint to initiate the connect account flow for linking a third-party account to the user's profile. |
154 | 156 | Redirects the user to the Auth0 connect account URL. |
155 | 157 | """ |
156 | | - authorization_params = { |
157 | | - k: v for k, v in request.query_params.items() if k not in ["connection", "returnTo"]} |
| 158 | + authorization_params = { |
| 159 | + k: v for k, v in request.query_params.items() if k not in ["connection", "returnTo", "scope"]} |
158 | 160 |
|
159 | | - return_to = request.query_params.get("returnTo") |
160 | 161 | connect_account_url = await auth_client.start_connect_account( |
161 | 162 | connection=connection, |
| 163 | + scopes=scopes, |
162 | 164 | app_state={"returnTo": return_to} if return_to else None, |
163 | 165 | authorization_params=authorization_params, |
164 | 166 | store_options={"request": request, "response": response}, |
|
0 commit comments