88import urllib .parse
99from typing import Tuple
1010from dataclasses import dataclass
11- import atproto_oauth_authn
11+ from .identity import resolve_identity
12+ from .did import retrieve_did_document , extract_pds_url
13+ from .metadata import get_pds_metadata , extract_auth_server , get_auth_server_metadata
14+ from .oauth import generate_oauth_state , generate_code_verifier , generate_code_challenge , send_par_request
15+ from . import security
1216from .exceptions import InvalidParameterError
1317
1418logging .basicConfig (
@@ -36,7 +40,7 @@ def resolve_user_did(username: str) -> str:
3640 """
3741 # Resolve the users DID
3842 try :
39- user_did = atproto_oauth_authn . resolve_identity (username )
43+ user_did = resolve_identity (username )
4044 except Exception as e :
4145 logging .error ("Failed to resolve username %s to a DID: %s" , username , e )
4246 raise
@@ -45,14 +49,14 @@ def resolve_user_did(username: str) -> str:
4549
4650 # Retrieve the user DID document
4751 try :
48- did_document = atproto_oauth_authn . retrieve_did_document (user_did )
52+ did_document = retrieve_did_document (user_did )
4953 except Exception as e :
5054 logging .error ("Failed to retrieve DID document for %s: %s" , user_did , e )
5155 raise
5256
5357 # Get the URL of the PDS server from the DID doc
5458 try :
55- pds_url = atproto_oauth_authn . extract_pds_url (did_document )
59+ pds_url = extract_pds_url (did_document )
5660 except Exception as e :
5761 logging .error ("Failed to extract PDS URL from DID document: %s" , e )
5862 raise
@@ -74,14 +78,14 @@ def discover_auth_server(pds_url: str) -> Tuple[str, str, str]:
7478 """
7579 # Get the PDS server metadata from the well-known endpoint
7680 try :
77- pds_metadata = atproto_oauth_authn . get_pds_metadata (pds_url )
81+ pds_metadata = get_pds_metadata (pds_url )
7882 except Exception as e :
7983 logging .error ("Failed to retrieve PDS metadata: %s" , e )
8084 raise
8185
8286 # From the metadata extract the authorization server
8387 try :
84- auth_servers = atproto_oauth_authn . extract_auth_server (pds_metadata )
88+ auth_servers = extract_auth_server (pds_metadata )
8589 except Exception as e :
8690 logging .error ("Failed to extract authorization server from metadata: %s" , e )
8791 raise
@@ -91,7 +95,7 @@ def discover_auth_server(pds_url: str) -> Tuple[str, str, str]:
9195 # Get the metadata of the authorization server
9296 try :
9397 auth_metadata , auth_endpoint , token_endpoint , par_endpoint = (
94- atproto_oauth_authn . get_auth_server_metadata (auth_servers )
98+ get_auth_server_metadata (auth_servers )
9599 )
96100 except Exception as e :
97101 logging .error ("Failed to retrieve auth server metadata: %s" , e )
@@ -118,7 +122,7 @@ def generate_oauth_params() -> Tuple[str, str, str]:
118122 """
119123 # Generate a state parameter for OAuth request
120124 try :
121- oauth_state = atproto_oauth_authn . generate_oauth_state ()
125+ oauth_state = generate_oauth_state ()
122126 except Exception as e :
123127 logging .error ("Failed to generate the oauth request: %s" , e )
124128 raise
@@ -127,7 +131,7 @@ def generate_oauth_params() -> Tuple[str, str, str]:
127131
128132 # Generate a code_verifier for PKCE
129133 try :
130- code_verifier = atproto_oauth_authn . generate_code_verifier (48 )
134+ code_verifier = generate_code_verifier (48 )
131135 except Exception as e :
132136 logging .error ("Failed to generate code verifier: %s" , e )
133137 raise
@@ -136,7 +140,7 @@ def generate_oauth_params() -> Tuple[str, str, str]:
136140
137141 # Generate a code_challenge from the code_verifier
138142 try :
139- code_challenge = atproto_oauth_authn . generate_code_challenge (code_verifier )
143+ code_challenge = generate_code_challenge (code_verifier )
140144 except Exception as e :
141145 logging .error ("Failed to generate code challenge: %s" , e )
142146 raise
@@ -222,7 +226,7 @@ def perform_par_request(context: PARRequestContext) -> Tuple[str, int]:
222226 )
223227 # Use the username as login_hint if available
224228 try :
225- request_uri , expires_in = atproto_oauth_authn . send_par_request (
229+ request_uri , expires_in = send_par_request (
226230 context = context ,
227231 )
228232 except Exception as e :
@@ -276,7 +280,7 @@ def get_authn_url(username: str, app_url: str) -> str:
276280 {"client_id" : client_id , "request_uri" : request_uri }
277281 )
278282 auth_url = f"{ auth_endpoint } ?{ qparam } "
279- assert atproto_oauth_authn . security .is_safe_url (auth_url )
283+ assert security .is_safe_url (auth_url )
280284
281285 logging .debug ("\n Authorization URL:" )
282286 logging .debug (
0 commit comments