Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/app/core/authentication/authentication.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ export class AuthenticationInterceptor implements HttpInterceptor {
* Intercepts a Http request and sets the request headers.
*/
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
// Skip Fineract auth headers for external API calls (e.g. remittance, national ID)
if (request.url.startsWith('http://') || request.url.startsWith('https://')) {
if (this.isExternalUrl(request.url)) {
return next.handle(request);
}
if (this.settingsService.tenantIdentifier) {
Expand All @@ -52,6 +51,23 @@ export class AuthenticationInterceptor implements HttpInterceptor {
return next.handle(request);
}

/**
* Absolute URLs pointing at our own Fineract server are internal — ApiPrefixInterceptor
* (in HttpService's dynamic chain) may have already converted relative URLs to absolute ones.
*/
private isExternalUrl(url: string): boolean {
try {
const requestOrigin = new URL(url).origin;
const server = this.settingsService.server;
if (server) {
return requestOrigin !== new URL(server).origin;
}
return true;
} catch {
return false; // Relative URL (new URL() throws) → internal
}
}

/**
* Sets the basic/oauth authorization header depending on the configuration.
* @param {string} authenticationKey Authentication key.
Expand Down
Loading