quankee-framework-interceptor 1.4.0 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { Injectable } from '@angular/core';
|
|
3
|
+
import { catchError, throwError } from 'rxjs';
|
|
3
4
|
import * as i1 from 'quankee-framework-keycloak';
|
|
4
5
|
|
|
5
6
|
function injectAuthHeader(req, token) {
|
|
@@ -21,9 +22,23 @@ class AuthorizationInterceptor {
|
|
|
21
22
|
intercept(req, next) {
|
|
22
23
|
console.log('[Interceptor] Executing...');
|
|
23
24
|
const token = this.keycloakService.getToken(); // returns string
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
let authReq = req;
|
|
26
|
+
if (token) {
|
|
27
|
+
console.log('[Interceptor] token found...' + token);
|
|
28
|
+
authReq = req.clone({
|
|
29
|
+
setHeaders: {
|
|
30
|
+
Authorization: `Bearer ${token}`,
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return next.handle(authReq).pipe(catchError((error) => {
|
|
35
|
+
console.error('HTTP Error:', error);
|
|
36
|
+
if (error.status === 401) {
|
|
37
|
+
// handle unauthorized
|
|
38
|
+
console.error('[Interceptor] Unauthorized.');
|
|
39
|
+
}
|
|
40
|
+
return throwError(() => error);
|
|
41
|
+
}));
|
|
27
42
|
}
|
|
28
43
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: AuthorizationInterceptor, deps: [{ token: i1.KeycloakService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
29
44
|
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: AuthorizationInterceptor });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quankee-framework-interceptor.mjs","sources":["../../../projects/quankee-framework-interceptor/src/lib/core/token.helper.ts","../../../projects/quankee-framework-interceptor/src/lib/core/authorization.interceptor.ts","../../../projects/quankee-framework-interceptor/src/public-api.ts","../../../projects/quankee-framework-interceptor/src/quankee-framework-interceptor.ts"],"sourcesContent":["export function injectAuthHeader(req: any, token: any): any {\n if (token) {\n return req.clone({\n setHeaders: {\n Authorization: `Bearer ${token}`,\n },\n });\n }\n return req;\n}\n","import {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from '@angular/common/http';\nimport {Injectable} from '@angular/core';\nimport {KeycloakService} from 'quankee-framework-keycloak';\nimport {Observable} from 'rxjs';\nimport {injectAuthHeader} from './token.helper';\n\n@Injectable()\nexport class AuthorizationInterceptor implements HttpInterceptor {\n\n constructor(private readonly keycloakService: KeycloakService) {}\n\n intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {\n console.log('[Interceptor] Executing...');\n\n const token = this.keycloakService.getToken(); // returns string\n
|
|
1
|
+
{"version":3,"file":"quankee-framework-interceptor.mjs","sources":["../../../projects/quankee-framework-interceptor/src/lib/core/token.helper.ts","../../../projects/quankee-framework-interceptor/src/lib/core/authorization.interceptor.ts","../../../projects/quankee-framework-interceptor/src/public-api.ts","../../../projects/quankee-framework-interceptor/src/quankee-framework-interceptor.ts"],"sourcesContent":["export function injectAuthHeader(req: any, token: any): any {\n if (token) {\n return req.clone({\n setHeaders: {\n Authorization: `Bearer ${token}`,\n },\n });\n }\n return req;\n}\n","import {HttpErrorResponse, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from '@angular/common/http';\nimport {Injectable} from '@angular/core';\nimport {KeycloakService} from 'quankee-framework-keycloak';\nimport {catchError, Observable, throwError} from 'rxjs';\nimport {injectAuthHeader} from './token.helper';\n\n@Injectable()\nexport class AuthorizationInterceptor implements HttpInterceptor {\n\n constructor(private readonly keycloakService: KeycloakService) {}\n\n intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {\n console.log('[Interceptor] Executing...');\n\n const token = this.keycloakService.getToken(); // returns string\n let authReq = req;\n\n if (token) {\n console.log('[Interceptor] token found...' + token);\n authReq = req.clone({\n setHeaders: {\n Authorization: `Bearer ${token}`,\n },\n });\n }\n return next.handle(authReq).pipe(\n catchError((error: HttpErrorResponse) => {\n console.error('HTTP Error:', error);\n if (error.status === 401) {\n // handle unauthorized\n console.error('[Interceptor] Unauthorized.')\n }\n return throwError(() => error);\n })\n );\n }\n}\n","/*\n * Public API Surface of quankee-framework-interceptor\n */\n\nexport * from './lib/core/token.helper';\nexport * from './lib/core/authorization.interceptor';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;AAAgB,SAAA,gBAAgB,CAAC,GAAQ,EAAE,KAAU,EAAA;IACnD,IAAI,KAAK,EAAE;QACT,OAAO,GAAG,CAAC,KAAK,CAAC;AACf,YAAA,UAAU,EAAE;gBACV,aAAa,EAAE,CAAU,OAAA,EAAA,KAAK,CAAE,CAAA;AACjC,aAAA;AACF,SAAA,CAAC;;AAEJ,IAAA,OAAO,GAAG;AACZ;;MCFa,wBAAwB,CAAA;AAEN,IAAA,eAAA;AAA7B,IAAA,WAAA,CAA6B,eAAgC,EAAA;QAAhC,IAAe,CAAA,eAAA,GAAf,eAAe;;IAE5C,SAAS,CAAC,GAAqB,EAAE,IAAiB,EAAA;AAChD,QAAA,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC;QAEzC,MAAM,KAAK,GAAG,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE,CAAC;QAC9C,IAAI,OAAO,GAAG,GAAG;QAEjB,IAAI,KAAK,EAAE;AACT,YAAA,OAAO,CAAC,GAAG,CAAC,8BAA8B,GAAG,KAAK,CAAC;AACnD,YAAA,OAAO,GAAG,GAAG,CAAC,KAAK,CAAC;AAClB,gBAAA,UAAU,EAAE;oBACV,aAAa,EAAE,CAAU,OAAA,EAAA,KAAK,CAAE,CAAA;AACjC,iBAAA;AACF,aA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