11
2- from fastapi import Request , Response , HTTPException , status
2+ # Imported from auth0-server-python
3+ from auth0_server_python .auth_server .server_client import ServerClient
4+ from auth0_server_python .auth_types import LogoutOptions , StartInteractiveLoginOptions
5+ from fastapi import HTTPException , Request , Response , status
36
7+ from auth0_fastapi .config import Auth0Config
48from auth0_fastapi .stores .cookie_transaction_store import CookieTransactionStore
59from auth0_fastapi .stores .stateless_state_store import StatelessStateStore
610
7- from auth0_fastapi .config import Auth0Config
8-
9- # Imported from auth0-server-python
10- from auth0_server_python .auth_server .server_client import ServerClient
11- from auth0_server_python .auth_types import (
12- StartInteractiveLoginOptions ,
13- LogoutOptions
14- )
15-
1611
1712class AuthClient :
1813 """
@@ -22,7 +17,12 @@ class AuthClient:
2217 logging out, and handling backchannel logout.
2318 """
2419
25- def __init__ (self , config : Auth0Config , state_store = None , transaction_store = None ):
20+ def __init__ (
21+ self ,
22+ config : Auth0Config ,
23+ state_store = None ,
24+ transaction_store = None ,
25+ ):
2626 self .config = config
2727 # Build the redirect URI based on the provided app_base_url
2828 redirect_uri = f"{ str (config .app_base_url ).rstrip ('/' )} /auth/callback"
@@ -48,11 +48,16 @@ def __init__(self, config: Auth0Config, state_store=None, transaction_store=None
4848 authorization_params = {
4949 "audience" : config .audience ,
5050 "redirect_uri" : redirect_uri ,
51- ** (config .authorization_params or {})
51+ ** (config .authorization_params or {}),
5252 },
5353 )
5454
55- async def start_login (self , app_state : dict = None , authorization_params : dict = None , store_options : dict = None ) -> str :
55+ async def start_login (
56+ self ,
57+ app_state : dict = None ,
58+ authorization_params : dict = None ,
59+ store_options : dict = None ,
60+ ) -> str :
5661 """
5762 Initiates the interactive login process.
5863 Optionally, an app_state dictionary can be passed to persist additional state.
@@ -62,32 +67,47 @@ async def start_login(self, app_state: dict = None, authorization_params: dict =
6267 options = StartInteractiveLoginOptions (
6368 pushed_authorization_requests = pushed_authorization_requests ,
6469 app_state = app_state ,
65- authorization_params = authorization_params if not pushed_authorization_requests else None
70+ authorization_params = authorization_params if not pushed_authorization_requests else None ,
6671 )
6772 return await self .client .start_interactive_login (options , store_options = store_options )
6873
69- async def complete_login (self , callback_url : str , store_options : dict = None ) -> dict :
74+ async def complete_login (
75+ self ,
76+ callback_url : str ,
77+ store_options : dict = None ,
78+ ) -> dict :
7079 """
7180 Completes the interactive login process using the callback URL.
7281 Returns a dictionary with the session state data.
7382 """
7483 return await self .client .complete_interactive_login (callback_url , store_options = store_options )
7584
76- async def logout (self , return_to : str = None , store_options : dict = None ) -> str :
85+ async def logout (
86+ self ,
87+ return_to : str = None ,
88+ store_options : dict = None ,
89+ ) -> str :
7790 """
7891 Initiates logout by clearing the session and generating a logout URL.
7992 Optionally accepts a return_to URL for redirection after logout.
8093 """
8194 options = LogoutOptions (return_to = return_to )
8295 return await self .client .logout (options , store_options = store_options )
8396
84- async def handle_backchannel_logout (self , logout_token : str ) -> None :
97+ async def handle_backchannel_logout (
98+ self ,
99+ logout_token : str ,
100+ ) -> None :
85101 """
86102 Processes a backchannel logout using the provided logout token.
87103 """
88104 return await self .client .handle_backchannel_logout (logout_token )
89105
90- async def start_link_user (self , options : dict , store_options : dict = None ) -> str :
106+ async def start_link_user (
107+ self ,
108+ options : dict ,
109+ store_options : dict = None ,
110+ ) -> str :
91111 """
92112 Initiates the user linking process.
93113 Options should include:
@@ -99,15 +119,23 @@ async def start_link_user(self, options: dict, store_options: dict = None) -> st
99119 """
100120 return await self .client .start_link_user (options , store_options = store_options )
101121
102- async def complete_link_user (self , url : str , store_options : dict = None ) -> dict :
122+ async def complete_link_user (
123+ self ,
124+ url : str ,
125+ store_options : dict = None ,
126+ ) -> dict :
103127 """
104128 Completes the user linking process.
105129 The provided URL should be the callback URL from Auth0.
106130 Returns a dictionary containing the original appState.
107131 """
108132 return await self .client .complete_link_user (url , store_options = store_options )
109133
110- async def start_unlink_user (self , options : dict , store_options : dict = None ) -> str :
134+ async def start_unlink_user (
135+ self ,
136+ options : dict ,
137+ store_options : dict = None ,
138+ ) -> str :
111139 """
112140 Initiates the user unlinking process.
113141 Options should include:
@@ -118,15 +146,23 @@ async def start_unlink_user(self, options: dict, store_options: dict = None) ->
118146 """
119147 return await self .client .start_unlink_user (options , store_options = store_options )
120148
121- async def complete_unlink_user (self , url : str , store_options : dict = None ) -> dict :
149+ async def complete_unlink_user (
150+ self ,
151+ url : str ,
152+ store_options : dict = None ,
153+ ) -> dict :
122154 """
123155 Completes the user unlinking process.
124156 The provided URL should be the callback URL from Auth0.
125157 Returns a dictionary containing the original appState.
126158 """
127159 return await self .client .complete_unlink_user (url , store_options = store_options )
128160
129- async def require_session (self , request : Request , response : Response ) -> dict :
161+ async def require_session (
162+ self ,
163+ request : Request ,
164+ response : Response ,
165+ ) -> dict :
130166 """
131167 Dependency method to ensure a session exists.
132168 Retrieves the session from the state store using the underlying client.
0 commit comments