Skip to content

Commit 38feedf

Browse files
author
KALLY\vytautas.pranskunas
committed
Improved url check in intercveptor by adding customUrlValidation
1 parent b4c8731 commit 38feedf

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

projects/lib/src/interceptors/default-oauth.interceptor.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { Observable } from 'rxjs';
1313
import { catchError } from 'rxjs/operators';
1414
import { OAuthResourceServerErrorHandler } from './resource-server-error-handler';
1515
import { OAuthModuleConfig } from '../oauth-module.config';
16+
import { isPlatformBrowser } from '@angular/common';
1617

1718
@Injectable()
1819
export class DefaultOAuthInterceptor implements HttpInterceptor {
@@ -23,8 +24,15 @@ export class DefaultOAuthInterceptor implements HttpInterceptor {
2324
) { }
2425

2526
private checkUrl(url: string): boolean {
26-
const found = this.moduleConfig.resourceServer.allowedUrls.find(u => url.startsWith(u));
27-
return !!found;
27+
if (this.moduleConfig.resourceServer.customUrlValidation) {
28+
return this.moduleConfig.resourceServer.customUrlValidation(url);
29+
}
30+
31+
if (this.moduleConfig.resourceServer.allowedUrls) {
32+
return !!this.moduleConfig.resourceServer.allowedUrls.find(u => url.startsWith(u));
33+
}
34+
35+
return true;
2836
}
2937

3038
public intercept(
@@ -39,7 +47,7 @@ export class DefaultOAuthInterceptor implements HttpInterceptor {
3947
if (!this.moduleConfig.resourceServer) {
4048
return next.handle(req);
4149
}
42-
if (this.moduleConfig.resourceServer.allowedUrls && !this.checkUrl(url)) {
50+
if (!this.checkUrl(url)) {
4351
return next.handle(req);
4452
}
4553

projects/lib/src/oauth-module.config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ export abstract class OAuthResourceServerConfig {
1010
*/
1111
allowedUrls?: Array<string>;
1212
sendAccessToken: boolean;
13+
customUrlValidation?: (url: string) => boolean;
1314
}

0 commit comments

Comments
 (0)