Skip to content

Commit ea24b5d

Browse files
committed
4.0.1
2 parents ed20fab + 90a1e99 commit ea24b5d

File tree

5 files changed

+1715
-1717
lines changed

5 files changed

+1715
-1717
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
## New Features in Version 4.0.0
4+
5+
See [Release Notes](https://github.com/manfredsteyer/angular-oauth2-oidc/releases/tag/4.0.0)
6+
37
## New Features in Version 3.1
48

59
See [Release Notes](https://github.com/manfredsteyer/angular-oauth2-oidc/releases/tag/3.1)

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Support for OAuth 2 and OpenId Connect (OIDC) in Angular.
1717
https://github.com/manfredsteyer/angular-oauth2-oidc
1818

1919
- Source Code Documentation
20-
https://manfredsteyer.github.io/angular-oauth2-oidc/angular-oauth2-oidc/docs/
20+
https://manfredsteyer.github.io/angular-oauth2-oidc/docs
2121

2222
## Tested Environment
2323

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

+40-45
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import { Injectable, Inject, Optional } from '@angular/core';
22
import { OAuthService } from '../oauth-service';
33
import { OAuthStorage } from '../types';
44
import {
5-
HttpEvent,
6-
HttpHandler,
7-
HttpInterceptor,
8-
HttpRequest,
9-
HttpResponse,
10-
HttpErrorResponse
5+
HttpEvent,
6+
HttpHandler,
7+
HttpInterceptor,
8+
HttpRequest,
9+
HttpResponse,
10+
HttpErrorResponse
1111
} from '@angular/common/http';
1212
import { Observable } from 'rxjs';
1313
import { catchError } from 'rxjs/operators';
@@ -16,51 +16,46 @@ import { OAuthModuleConfig } from '../oauth-module.config';
1616

1717
@Injectable()
1818
export class DefaultOAuthInterceptor implements HttpInterceptor {
19-
constructor(
20-
private authStorage: OAuthStorage,
21-
private errorHandler: OAuthResourceServerErrorHandler,
22-
@Optional() private moduleConfig: OAuthModuleConfig
23-
) {}
19+
constructor(
20+
private authStorage: OAuthStorage,
21+
private errorHandler: OAuthResourceServerErrorHandler,
22+
@Optional() private moduleConfig: OAuthModuleConfig
23+
) { }
24+
25+
private checkUrl(url: string): boolean {
26+
const found = this.moduleConfig.resourceServer.allowedUrls.find(u => url.startsWith(u));
27+
return !!found;
28+
}
2429

25-
private checkUrl(url: string): boolean {
26-
const found = this.moduleConfig.resourceServer.allowedUrls.find(u =>
27-
url.startsWith(u)
28-
);
29-
return !!found;
30-
}
30+
public intercept(
31+
req: HttpRequest<any>,
32+
next: HttpHandler
33+
): Observable<HttpEvent<any>> {
34+
const url = req.url.toLowerCase();
3135

32-
public intercept(
33-
req: HttpRequest<any>,
34-
next: HttpHandler
35-
): Observable<HttpEvent<any>> {
36-
const url = req.url.toLowerCase();
36+
if (!this.moduleConfig) {
37+
return next.handle(req);
38+
}
39+
if (!this.moduleConfig.resourceServer) {
40+
return next.handle(req);
41+
}
42+
if (this.moduleConfig.resourceServer.allowedUrls && !this.checkUrl(url)) {
43+
return next.handle(req);
44+
}
3745

38-
if (!this.moduleConfig) {
39-
return next.handle(req);
40-
}
41-
if (!this.moduleConfig.resourceServer) {
42-
return next.handle(req);
43-
}
44-
if (!this.moduleConfig.resourceServer.allowedUrls) {
45-
return next.handle(req);
46-
}
47-
if (!this.checkUrl(url)) {
48-
return next.handle(req);
49-
}
46+
const sendAccessToken = this.moduleConfig.resourceServer.sendAccessToken;
5047

51-
const sendAccessToken = this.moduleConfig.resourceServer.sendAccessToken;
48+
if (sendAccessToken && this.authStorage.getItem('access_token')) {
49+
const token = this.authStorage.getItem('access_token');
50+
const header = 'Bearer ' + token;
5251

53-
if (sendAccessToken && this.authStorage.getItem('access_token')) {
54-
const token = this.authStorage.getItem('access_token');
55-
const header = 'Bearer ' + token;
52+
const headers = req.headers.set('Authorization', header);
5653

57-
const headers = req.headers.set('Authorization', header);
54+
req = req.clone({ headers });
55+
}
5856

59-
req = req.clone({ headers });
57+
return next
58+
.handle(req)
59+
.pipe(catchError(err => this.errorHandler.handleError(err)));
6060
}
61-
62-
return next
63-
.handle(req)
64-
.pipe(catchError(err => this.errorHandler.handleError(err)));
65-
}
6661
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ export abstract class OAuthResourceServerConfig {
88
* If there is an ResourceServerErrorHandler registered, it is used for them.
99
* If sendAccessToken is set to true, the access_token is send to them too.
1010
*/
11-
allowedUrls: Array<string>;
11+
allowedUrls?: Array<string>;
1212
sendAccessToken: boolean;
1313
}

0 commit comments

Comments
 (0)