Redirects the user to the OAuth provider for authentication.
(request: Request, body: OAuthSchema)
| 456 | |
| 457 | @public_route |
| 458 | async def auth_oauth(request: Request, body: OAuthSchema) -> RedirectMessageResponse: |
| 459 | """ |
| 460 | Redirects the user to the OAuth provider for authentication. |
| 461 | """ |
| 462 | supabase = get_supabase() |
| 463 | provider = body.provider |
| 464 | redirect_url = f"{API_URL}{reverse_path('auth_code')}" |
| 465 | |
| 466 | if provider not in OAUTH_SCOPES: |
| 467 | raise AuthException(f"Unsupported OAuth provider: {provider}") |
| 468 | |
| 469 | # TODO re-enable this once invalid redirect destinations have been fixed in `auth_code` |
| 470 | # if body.redirect_to: |
| 471 | # params = urllib.parse.urlencode({"redirect_to": body.redirect_to}) |
| 472 | # redirect_url += f"?redirect_to={params}" |
| 473 | |
| 474 | try: |
| 475 | auth_response = supabase.auth.sign_in_with_oauth( |
| 476 | { |
| 477 | 'provider': provider, |
| 478 | 'options': { |
| 479 | 'redirect_to': redirect_url, |
| 480 | 'scopes': OAUTH_SCOPES[provider], |
| 481 | }, |
| 482 | } |
| 483 | ) |
| 484 | except gotrue.errors.AuthApiError as e: |
| 485 | raise AuthException.from_gotrue_autherror(e) |
| 486 | |
| 487 | if hasattr(auth_response, 'error'): |
| 488 | raise AuthException("Failed to initiate OAuth flow.") |
| 489 | |
| 490 | return RedirectMessageResponse( |
| 491 | message="Redirecting to OAuth provider...", |
| 492 | url=auth_response.url, |
| 493 | ) |
| 494 | |
| 495 | |
| 496 | @public_route |
nothing calls this directly
no test coverage detected
searching dependent graphs…