Skip to content

Commit c9dab93

Browse files
committed
refactor: update authentication URL configuration for Keycloak
- Replaced direct references to OIDC_CONFIG with environment variables for OIDC_SERVER_URL, OIDC_REALM, OIDC_CLIENT_ID, and OIDC_CLIENT_SECRET, enhancing configuration management. - Improved code clarity and maintainability by centralizing authentication URL generation in the config module.
1 parent 01499cc commit c9dab93

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/backend/config.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,18 @@ def delete_session(session_id: str) -> None:
7171

7272
def get_auth_url() -> str:
7373
"""Generate the authentication URL for Keycloak login"""
74-
auth_url = f"{OIDC_CONFIG['server_url']}/realms/{OIDC_CONFIG['realm']}/protocol/openid-connect/auth"
74+
auth_url = f"{OIDC_SERVER_URL}/realms/{OIDC_REALM}/protocol/openid-connect/auth"
7575
params = {
76-
'client_id': OIDC_CONFIG['client_id'],
76+
'client_id': OIDC_CLIENT_ID,
7777
'response_type': 'code',
78-
'redirect_uri': OIDC_CONFIG['redirect_uri'],
78+
'redirect_uri': OIDC_REDIRECT_URI,
7979
'scope': 'openid profile email'
8080
}
8181
return f"{auth_url}?{'&'.join(f'{k}={v}' for k,v in params.items())}"
8282

8383
def get_token_url() -> str:
8484
"""Get the token endpoint URL"""
85-
return f"{OIDC_CONFIG['server_url']}/realms/{OIDC_CONFIG['realm']}/protocol/openid-connect/token"
85+
return f"{OIDC_SERVER_URL}/realms/{OIDC_REALM}/protocol/openid-connect/token"
8686

8787
def is_token_expired(token_data: Dict[str, Any], buffer_seconds: int = 30) -> bool:
8888
"""
@@ -132,8 +132,8 @@ async def refresh_token(session_id: str, token_data: Dict[str, Any]) -> Tuple[bo
132132
get_token_url(),
133133
data={
134134
'grant_type': 'refresh_token',
135-
'client_id': OIDC_CONFIG['client_id'],
136-
'client_secret': OIDC_CONFIG['client_secret'],
135+
'client_id': OIDC_CLIENT_ID,
136+
'client_secret': OIDC_CLIENT_SECRET,
137137
'refresh_token': token_data['refresh_token']
138138
}
139139
)

0 commit comments

Comments
 (0)