Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d66c82a

Browse files
authoredJul 17, 2019
Merge pull request #331 from vytautas-pranskunas-/master
Added customUrlValidation
2 parents 9ed3cd6 + 44532af commit d66c82a

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed
 

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

Lines changed: 11 additions & 3 deletions
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

Lines changed: 1 addition & 0 deletions
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
}

‎projects/lib/src/oauth-service.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,11 +1691,15 @@ export class OAuthService extends AuthConfig implements OnDestroy {
16911691
* Returns the current access_token.
16921692
*/
16931693
public getAccessToken(): string {
1694-
return this._storage.getItem('access_token');
1694+
return this._storage
1695+
? this._storage.getItem('access_token')
1696+
: null;
16951697
}
16961698

16971699
public getRefreshToken(): string {
1698-
return this._storage.getItem('refresh_token');
1700+
return this._storage
1701+
? this._storage.getItem('refresh_token')
1702+
: null;
16991703
}
17001704

17011705
/**

0 commit comments

Comments
 (0)
Please sign in to comment.