Skip to content

Commit 49069a0

Browse files
committed
Mount connected account start flow on the auth/connect route and make mutually exclusive with legacy connect behaviour
1 parent ac1ed9c commit 49069a0

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/auth0_fastapi/errors/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212
from fastapi.responses import JSONResponse
1313

1414

15+
class ConfigurationError(Auth0Error):
16+
"""
17+
Error raised when an invalid configuration is used.
18+
"""
19+
code = "configuration_error"
20+
21+
def __init__(self, message=None):
22+
super().__init__(message or "An invalid configuration was provided.")
23+
self.name = "ConfigurationError"
24+
1525
def auth0_exception_handler(request: Request, exc: Auth0Error):
1626
"""
1727
Exception handler for Auth0 SDK errors.

src/auth0_fastapi/server/routes.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from ..auth.auth_client import AuthClient
77
from ..config import Auth0Config
88
from ..util import create_route_url, to_safe_redirect
9+
from ..errors import ConfigurationError
910

1011
router = APIRouter()
1112

@@ -26,6 +27,13 @@ def register_auth_routes(router: APIRouter, config: Auth0Config):
2627
"""
2728
Conditionally register auth routes based on config.mount_routes and config.mount_connect_routes.
2829
"""
30+
if config.mount_connect_routes and config.mount_connected_account_routes:
31+
# Connect routes uses the legacy account linking flow for token vault
32+
# Connects Accounts is the preferred mechanism
33+
# Both mount the `/auth/connect` route to initiate the flow
34+
raise ConfigurationError(
35+
"'mount_connect_routes' and 'mount_connected_account_routes' cannot be used together.")
36+
2937
if config.mount_routes:
3038
@router.get("/auth/login")
3139
async def login(
@@ -134,7 +142,7 @@ async def backchannel_logout(
134142
return Response(status_code=204)
135143

136144
if config.mount_connected_account_routes:
137-
@router.get("/auth/connect-account")
145+
@router.get("/auth/connect")
138146
async def connect_account(
139147
request: Request,
140148
response: Response,

0 commit comments

Comments
 (0)