Skip to content

Commit d951450

Browse files
committed
WEB-579: make API gateway tenant header name configurable
1 parent afebb0e commit d951450

4 files changed

Lines changed: 36 additions & 6 deletions

File tree

src/app/login/login.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ export class LoginComponent implements OnInit, OnDestroy {
208208
}
209209
const tenantIds = environment.fineractPlatformTenantIds
210210
.split(',')
211-
.map((id) => id.trim())
212-
.filter((id) => id.length > 0);
211+
.map((id: string) => id.trim())
212+
.filter((id: string) => id.length > 0);
213213
if (tenantIds.length === 0 || (tenantIds.length === 1 && tenantIds[0] === 'default')) {
214214
return false;
215215
}

src/app/zitadel/token.interceptor.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@ export class TokenInterceptor implements HttpInterceptor {
1919

2020
public environment = environment;
2121
FINERACT_PLATFORM_TENANT_IDENTIFIER = environment.fineractPlatformTenantId;
22+
// Name used to send the Fineract tenant identifier header.
23+
// The runtime key is `apiGatewayHeaderName` to allow gateway/runtime injection,
24+
// but this value represents the Fineract tenant header name.
25+
FINERACT_TENANT_HEADER_NAME = environment.apiGatewayHeaderName || 'Fineract-Platform-TenantId';
2226

2327
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
2428
const token = this.authService.getAccessToken();
2529
let headersConfig: { [key: string]: string } = {
26-
'Fineract-Platform-TenantId': this.FINERACT_PLATFORM_TENANT_IDENTIFIER,
30+
[this.FINERACT_TENANT_HEADER_NAME]: this.FINERACT_PLATFORM_TENANT_IDENTIFIER,
2731
'Content-Type': req.headers.get('Content-Type') || 'application/json'
2832
};
2933
const publicEndpoints = [
@@ -56,7 +60,7 @@ export class TokenInterceptor implements HttpInterceptor {
5660
const retriedReq = request.clone({
5761
setHeaders: {
5862
Authorization: `Bearer ${newToken}`,
59-
'Fineract-Platform-TenantId': this.FINERACT_PLATFORM_TENANT_IDENTIFIER,
63+
[this.FINERACT_TENANT_HEADER_NAME]: this.FINERACT_PLATFORM_TENANT_IDENTIFIER,
6064
'Content-Type': request.headers.get('Content-Type') || 'application/json'
6165
}
6266
});

src/environments/environment.prod.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ const provider = loadedEnv['apiProvider'];
1717
const parsedMinLength = Number(loadedEnv.minPasswordLength);
1818
const resolvedMinPasswordLength = Number.isInteger(parsedMinLength) && parsedMinLength > 0 ? parsedMinLength : 8;
1919

20+
// Validate and normalize apiGatewayHeaderName (RFC 7230 token format)
21+
const resolvedApiGatewayHeaderName =
22+
typeof loadedEnv.apiGatewayHeaderName === 'string' &&
23+
/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/.test(loadedEnv.apiGatewayHeaderName.trim())
24+
? loadedEnv.apiGatewayHeaderName.trim()
25+
: 'Fineract-Platform-TenantId';
26+
2027
export const environment = {
2128
production: true,
2229
version: env.mifos_x.version,
@@ -145,7 +152,13 @@ export const environment = {
145152
oidcClientId: loadedEnv['oidcClientId'] || loadedEnv['FINERACT_PLUGIN_OIDC_CLIENT_ID'] || '',
146153
oidcApiUrl: loadedEnv['oidcApiUrl'] || loadedEnv['FINERACT_PLUGIN_OIDC_API_URL'] || '',
147154
oidcFrontUrl: loadedEnv['oidcFrontUrl'] || loadedEnv['FINERACT_PLUGIN_OIDC_FRONTEND_URL'] || ''
148-
}
155+
},
156+
/**
157+
* Name of the header used to signal the tenant/platform to the API gateway
158+
* Default kept for backward compatibility with existing deployments and tests
159+
* Validated against RFC 7230 token format; whitespace trimmed; invalid values fallback to default.
160+
*/
161+
apiGatewayHeaderName: resolvedApiGatewayHeaderName
149162
};
150163

151164
// Server URL

src/environments/environment.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ const loadedEnv = window.env || {};
2020
const parsedMinLength = Number(loadedEnv.minPasswordLength);
2121
const resolvedMinPasswordLength = Number.isInteger(parsedMinLength) && parsedMinLength > 0 ? parsedMinLength : 8;
2222

23+
// Validate and normalize apiGatewayHeaderName (RFC 7230 token format)
24+
const resolvedApiGatewayHeaderName =
25+
typeof loadedEnv.apiGatewayHeaderName === 'string' &&
26+
/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/.test(loadedEnv.apiGatewayHeaderName.trim())
27+
? loadedEnv.apiGatewayHeaderName.trim()
28+
: 'Fineract-Platform-TenantId';
29+
2330
export const environment = {
2431
production: false,
2532
version: env.mifos_x.version,
@@ -149,7 +156,13 @@ export const environment = {
149156
oidcClientId: loadedEnv.oidcClientId || loadedEnv.FINERACT_PLUGIN_OIDC_CLIENT_ID || '',
150157
oidcApiUrl: loadedEnv.oidcApiUrl || loadedEnv.FINERACT_PLUGIN_OIDC_API_URL || '',
151158
oidcFrontUrl: loadedEnv.oidcFrontUrl || loadedEnv.FINERACT_PLUGIN_OIDC_FRONTEND_URL || ''
152-
}
159+
},
160+
/**
161+
* Name of the header used to signal the tenant/platform to the API gateway
162+
* Default kept for backward compatibility with existing deployments and tests
163+
* Validated against RFC 7230 token format; whitespace trimmed; invalid values fallback to default.
164+
*/
165+
apiGatewayHeaderName: resolvedApiGatewayHeaderName
153166
};
154167

155168
// Server URL

0 commit comments

Comments
 (0)