@@ -61,21 +61,35 @@ function getOIDCConfig(): AuthConfig {
6161}
6262
6363/**
64- * Creates the configuration required for classic OAuth2 providers (e.g., Fineract).
64+ * Creates the configuration required for classic OAuth2 providers (e.g., Fineract, Keycloak ).
6565 * @returns {AuthConfig } OAuth2 configuration block.
6666 */
6767function getOAuth2Config ( ) : AuthConfig {
6868 const frontendUrl = window . location . origin ;
69+ const { serverUrl, authorizeUrl, tokenUrl, redirectUri, scope, appId } = environment . oauth ;
70+ const normalizedServerUrl = serverUrl ?. replace ( / \/ $ / , '' ) || '' ;
71+
72+ // Allow custom Keycloak realm via MIFOS_OAUTH_REALM (defaults to master)
73+ const keycloakRealm = ( window as any ) [ 'env' ] ?. [ 'MIFOS_OAUTH_REALM' ] || 'master' ;
74+ const resolvedAuthorizeUrl =
75+ authorizeUrl || `${ normalizedServerUrl } /auth/realms/${ keycloakRealm } /protocol/openid-connect/auth` ;
76+ const resolvedTokenUrl =
77+ tokenUrl || `${ normalizedServerUrl } /auth/realms/${ keycloakRealm } /protocol/openid-connect/token` ;
78+ const resolvedRedirectUri = redirectUri || `${ frontendUrl } /#/callback` ;
79+ const resolvedScope = scope || 'openid profile email' ;
80+
81+ // For Keycloak, issuer should be the realm URL for correct OAuth2 semantics
82+ const issuerUrl = authorizeUrl ? normalizedServerUrl : `${ normalizedServerUrl } /auth/realms/${ keycloakRealm } ` ;
6983
7084 return {
71- issuer : environment . oauth . serverUrl ,
72- loginUrl : environment . oauth . authorizeUrl ,
73- tokenEndpoint : environment . oauth . tokenUrl ,
74- redirectUri : environment . oauth . redirectUri ,
85+ issuer : issuerUrl ,
86+ loginUrl : resolvedAuthorizeUrl ,
87+ tokenEndpoint : resolvedTokenUrl ,
88+ redirectUri : resolvedRedirectUri ,
7589 postLogoutRedirectUri : `${ frontendUrl } /#/login` ,
76- clientId : environment . oauth . appId ,
90+ clientId : appId ,
7791 responseType : 'code' ,
78- scope : environment . oauth . scope ,
92+ scope : resolvedScope ,
7993 useSilentRefresh : false ,
8094 oidc : false ,
8195 // Skip issuer validation for OAuth2 (non-OIDC) flows
0 commit comments