Skip to content

Commit f4d8dbf

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

3 files changed

Lines changed: 43 additions & 6 deletions

File tree

src/app/zitadel/token.interceptor.ts

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

2020
public environment = environment;
2121
FINERACT_PLATFORM_TENANT_IDENTIFIER = environment.fineractPlatformTenantId;
22+
API_GATEWAY_HEADER_NAME = environment.apiGatewayHeaderName || 'Fineract-Platform-TenantId';
2223

2324
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
2425
const token = this.authService.getAccessToken();
2526
let headersConfig: { [key: string]: string } = {
26-
'Fineract-Platform-TenantId': this.FINERACT_PLATFORM_TENANT_IDENTIFIER,
27+
[this.API_GATEWAY_HEADER_NAME]: this.FINERACT_PLATFORM_TENANT_IDENTIFIER,
2728
'Content-Type': req.headers.get('Content-Type') || 'application/json'
2829
};
2930
const publicEndpoints = [
@@ -56,7 +57,7 @@ export class TokenInterceptor implements HttpInterceptor {
5657
const retriedReq = request.clone({
5758
setHeaders: {
5859
Authorization: `Bearer ${newToken}`,
59-
'Fineract-Platform-TenantId': this.FINERACT_PLATFORM_TENANT_IDENTIFIER,
60+
[this.API_GATEWAY_HEADER_NAME]: this.FINERACT_PLATFORM_TENANT_IDENTIFIER,
6061
'Content-Type': request.headers.get('Content-Type') || 'application/json'
6162
}
6263
});

src/environments/environment.prod.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,19 @@ const provider = loadedEnv['apiProvider'];
1717
const parsedMinLength = Number(loadedEnv.minPasswordLength);
1818
const resolvedMinPasswordLength = Number.isInteger(parsedMinLength) && parsedMinLength > 0 ? parsedMinLength : 8;
1919

20-
export const environment = {
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+
27+
interface IEnvironment {
28+
[key: string]: any;
29+
apiGatewayHeaderName: string;
30+
}
31+
32+
export const environment: IEnvironment = {
2133
production: true,
2234
version: env.mifos_x.version,
2335
hash: env.mifos_x.hash,
@@ -145,7 +157,13 @@ export const environment = {
145157
oidcClientId: loadedEnv['oidcClientId'] || loadedEnv['FINERACT_PLUGIN_OIDC_CLIENT_ID'] || '',
146158
oidcApiUrl: loadedEnv['oidcApiUrl'] || loadedEnv['FINERACT_PLUGIN_OIDC_API_URL'] || '',
147159
oidcFrontUrl: loadedEnv['oidcFrontUrl'] || loadedEnv['FINERACT_PLUGIN_OIDC_FRONTEND_URL'] || ''
148-
}
160+
},
161+
/**
162+
* Name of the header used to signal the tenant/platform to the API gateway
163+
* Default kept for backward compatibility with existing deployments and tests
164+
* Validated against RFC 7230 token format; whitespace trimmed; invalid values fallback to default.
165+
*/
166+
apiGatewayHeaderName: resolvedApiGatewayHeaderName
149167
};
150168

151169
// Server URL

src/environments/environment.ts

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

23-
export const environment = {
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+
30+
interface IEnvironment {
31+
[key: string]: any;
32+
apiGatewayHeaderName: string;
33+
}
34+
35+
export const environment: IEnvironment = {
2436
production: false,
2537
version: env.mifos_x.version,
2638
hash: env.mifos_x.hash,
@@ -149,7 +161,13 @@ export const environment = {
149161
oidcClientId: loadedEnv.oidcClientId || loadedEnv.FINERACT_PLUGIN_OIDC_CLIENT_ID || '',
150162
oidcApiUrl: loadedEnv.oidcApiUrl || loadedEnv.FINERACT_PLUGIN_OIDC_API_URL || '',
151163
oidcFrontUrl: loadedEnv.oidcFrontUrl || loadedEnv.FINERACT_PLUGIN_OIDC_FRONTEND_URL || ''
152-
}
164+
},
165+
/**
166+
* Name of the header used to signal the tenant/platform to the API gateway
167+
* Default kept for backward compatibility with existing deployments and tests
168+
* Validated against RFC 7230 token format; whitespace trimmed; invalid values fallback to default.
169+
*/
170+
apiGatewayHeaderName: resolvedApiGatewayHeaderName
153171
};
154172

155173
// Server URL

0 commit comments

Comments
 (0)