1111EDA_REALM = "eda"
1212API_CLIENT_ID = "eda"
1313
14- # Step 1: Get an access token
15- token_url = f"{ KC_KEYCLOAK_URL } /realms/{ KC_REALM } /protocol/openid-connect/token"
16- token_data = {
17- "grant_type" : "password" ,
18- "client_id" : KC_CLIENT_ID ,
19- "username" : KC_USERNAME ,
20- "password" : KC_PASSWORD ,
21- }
22- headers = {"Content-Type" : "application/x-www-form-urlencoded" }
2314
15+ def get_client_secret () -> str :
16+ with httpx .Client (verify = False ) as client :
17+ token_url = f"{ KC_KEYCLOAK_URL } /realms/{ KC_REALM } /protocol/openid-connect/token"
18+ token_data = {
19+ "grant_type" : "password" ,
20+ "client_id" : KC_CLIENT_ID ,
21+ "username" : KC_USERNAME ,
22+ "password" : KC_PASSWORD ,
23+ }
24+ headers = {"Content-Type" : "application/x-www-form-urlencoded" }
2425
25- async def get_client_secret () -> str :
26- async with httpx .AsyncClient (verify = False ) as client :
2726 # Fetch access token
28- token_response = await client .post (token_url , data = token_data , headers = headers )
27+ token_response = client .post (token_url , data = token_data , headers = headers )
2928 token_response .raise_for_status ()
3029 access_token = token_response .json ()["access_token" ]
3130
@@ -37,7 +36,7 @@ async def get_client_secret() -> str:
3736 }
3837
3938 # Fetch clients
40- clients_response = await client .get (admin_api_url , headers = auth_headers )
39+ clients_response = client .get (admin_api_url , headers = auth_headers )
4140 clients_response .raise_for_status ()
4241 clients = clients_response .json ()
4342
@@ -52,14 +51,14 @@ async def get_client_secret() -> str:
5251 # Fetch the client secret
5352 client_id = eda_client ["id" ]
5453 client_secret_url = f"{ admin_api_url } /{ client_id } /client-secret"
55- secret_response = await client .get (client_secret_url , headers = auth_headers )
54+ secret_response = client .get (client_secret_url , headers = auth_headers )
5655 secret_response .raise_for_status ()
5756 client_secret = secret_response .json ()["value" ]
5857
5958 return client_secret
6059
6160
62- async def get_access_token (client_secret : str ) -> str :
61+ def get_access_token (client_secret : str ) -> str :
6362 token_endpoint = (
6463 f"{ KC_KEYCLOAK_URL } /realms/{ EDA_REALM } /protocol/openid-connect/token"
6564 )
@@ -75,7 +74,7 @@ async def get_access_token(client_secret: str) -> str:
7574
7675 headers = {"Content-Type" : "application/x-www-form-urlencoded" }
7776
78- async with httpx .AsyncClient (verify = False ) as client :
79- response = await client .post (token_endpoint , data = token_data , headers = headers )
77+ with httpx .Client (verify = False ) as client :
78+ response = client .post (token_endpoint , data = token_data , headers = headers )
8079 response .raise_for_status ()
8180 return response .json ()["access_token" ]
0 commit comments