Skip to content

Commit

Permalink
4.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
manfredsteyer committed May 15, 2018
2 parents ed20fab + 90a1e99 commit ea24b5d
Show file tree
Hide file tree
Showing 5 changed files with 1,715 additions and 1,717 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## New Features in Version 4.0.0

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

## New Features in Version 3.1

See [Release Notes](https://github.com/manfredsteyer/angular-oauth2-oidc/releases/tag/3.1)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Support for OAuth 2 and OpenId Connect (OIDC) in Angular.
https://github.com/manfredsteyer/angular-oauth2-oidc

- Source Code Documentation
https://manfredsteyer.github.io/angular-oauth2-oidc/angular-oauth2-oidc/docs/
https://manfredsteyer.github.io/angular-oauth2-oidc/docs

## Tested Environment

Expand Down
85 changes: 40 additions & 45 deletions projects/lib/src/interceptors/default-oauth.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { Injectable, Inject, Optional } from '@angular/core';
import { OAuthService } from '../oauth-service';
import { OAuthStorage } from '../types';
import {
HttpEvent,
HttpHandler,
HttpInterceptor,
HttpRequest,
HttpResponse,
HttpErrorResponse
HttpEvent,
HttpHandler,
HttpInterceptor,
HttpRequest,
HttpResponse,
HttpErrorResponse
} from '@angular/common/http';
import { Observable } from 'rxjs';
import { catchError } from 'rxjs/operators';
Expand All @@ -16,51 +16,46 @@ import { OAuthModuleConfig } from '../oauth-module.config';

@Injectable()
export class DefaultOAuthInterceptor implements HttpInterceptor {
constructor(
private authStorage: OAuthStorage,
private errorHandler: OAuthResourceServerErrorHandler,
@Optional() private moduleConfig: OAuthModuleConfig
) {}
constructor(
private authStorage: OAuthStorage,
private errorHandler: OAuthResourceServerErrorHandler,
@Optional() private moduleConfig: OAuthModuleConfig
) { }

private checkUrl(url: string): boolean {
const found = this.moduleConfig.resourceServer.allowedUrls.find(u => url.startsWith(u));
return !!found;
}

private checkUrl(url: string): boolean {
const found = this.moduleConfig.resourceServer.allowedUrls.find(u =>
url.startsWith(u)
);
return !!found;
}
public intercept(
req: HttpRequest<any>,
next: HttpHandler
): Observable<HttpEvent<any>> {
const url = req.url.toLowerCase();

public intercept(
req: HttpRequest<any>,
next: HttpHandler
): Observable<HttpEvent<any>> {
const url = req.url.toLowerCase();
if (!this.moduleConfig) {
return next.handle(req);
}
if (!this.moduleConfig.resourceServer) {
return next.handle(req);
}
if (this.moduleConfig.resourceServer.allowedUrls && !this.checkUrl(url)) {
return next.handle(req);
}

if (!this.moduleConfig) {
return next.handle(req);
}
if (!this.moduleConfig.resourceServer) {
return next.handle(req);
}
if (!this.moduleConfig.resourceServer.allowedUrls) {
return next.handle(req);
}
if (!this.checkUrl(url)) {
return next.handle(req);
}
const sendAccessToken = this.moduleConfig.resourceServer.sendAccessToken;

const sendAccessToken = this.moduleConfig.resourceServer.sendAccessToken;
if (sendAccessToken && this.authStorage.getItem('access_token')) {
const token = this.authStorage.getItem('access_token');
const header = 'Bearer ' + token;

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

const headers = req.headers.set('Authorization', header);
req = req.clone({ headers });
}

req = req.clone({ headers });
return next
.handle(req)
.pipe(catchError(err => this.errorHandler.handleError(err)));
}

return next
.handle(req)
.pipe(catchError(err => this.errorHandler.handleError(err)));
}
}
2 changes: 1 addition & 1 deletion projects/lib/src/oauth-module.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ export abstract class OAuthResourceServerConfig {
* If there is an ResourceServerErrorHandler registered, it is used for them.
* If sendAccessToken is set to true, the access_token is send to them too.
*/
allowedUrls: Array<string>;
allowedUrls?: Array<string>;
sendAccessToken: boolean;
}
Loading

0 comments on commit ea24b5d

Please sign in to comment.