Skip to content

Commit ca87a45

Browse files
authored
Merge pull request #1220 from linjie997/remove-jsrsasign
Remove jsrsasign
2 parents 449be6f + 0da8b29 commit ca87a45

31 files changed

+1164
-16347
lines changed

package-lock.json

Lines changed: 15 additions & 15514 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
"@angular/platform-browser-dynamic": "~13.0.1",
6565
"@angular/router": "~13.0.1",
6666
"@schematics/angular": "~13.0.1",
67-
"jsrsasign-reduced": "^8.0.15",
6867
"rxjs": "^7.4.0",
6968
"tslib": "^2.1.0",
7069
"zone.js": "~0.11.4"
@@ -101,6 +100,7 @@
101100
"ng-packagr": "^13.0.3",
102101
"prettier": "^2.2.1",
103102
"protractor": "~7.0.0",
103+
"rfc4648": "^1.5.0",
104104
"ts-node": "~8.3.0",
105105
"tslint": "~6.1.0",
106106
"typescript": "~4.4.3"

projects/angular-auth-oidc-client/ng-package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
"lib": {
55
"entryFile": "src/public-api.ts"
66
},
7-
"allowedNonPeerDependencies": ["jsrsasign-reduced", "@angular-devkit/core", "@schematics/angular", "@angular-devkit/schematics"]
7+
"allowedNonPeerDependencies": ["rfc4648", "@angular-devkit/core", "@schematics/angular", "@angular-devkit/schematics"]
88
}

projects/angular-auth-oidc-client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"dependencies": {
1111
"tslib": "^2.3.0",
12-
"jsrsasign-reduced": "^8.0.15"
12+
"rfc4648": "^1.5.0"
1313
},
1414
"repository": {
1515
"type": "git",

projects/angular-auth-oidc-client/src/lib/config/auth-well-known/auth-well-known.service-mock.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { Injectable } from '@angular/core';
2+
import { Observable, of } from 'rxjs';
23
import { AuthWellKnownEndpoints } from './auth-well-known-endpoints';
34

45
@Injectable()
56
export class AuthWellKnownServiceMock {
6-
getAuthWellKnownEndPoints(authWellknownEndpoint: string) {
7-
return null;
7+
getAuthWellKnownEndPoints(authWellknownEndpoint: string): Observable<AuthWellKnownEndpoints> {
8+
return of(null);
89
}
910

1011
storeWellKnownEndpoints(mappedWellKnownEndpoints: AuthWellKnownEndpoints) {}

projects/angular-auth-oidc-client/src/lib/flows/callback-context.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ export interface AuthResult {
2121
error?: any;
2222
// eslint-disable-next-line @typescript-eslint/naming-convention
2323
session_state?: any;
24+
state?: any;
2425
}

projects/angular-auth-oidc-client/src/lib/flows/callback-handling/state-validation-callback-handler.service.spec.ts

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { CallbackContext } from '../callback-context';
1212
import { ResetAuthDataService } from '../reset-auth-data.service';
1313
import { ResetAuthDataServiceMock } from '../reset-auth-data.service-mock';
1414
import { StateValidationCallbackHandlerService } from './state-validation-callback-handler.service';
15+
import { of } from 'rxjs';
1516

1617
describe('StateValidationCallbackHandlerService', () => {
1718
let service: StateValidationCallbackHandlerService;
@@ -35,7 +36,8 @@ describe('StateValidationCallbackHandlerService', () => {
3536
get hash() {
3637
return '&anyFakeHash';
3738
},
38-
set hash(v) {},
39+
set hash(v) {
40+
},
3941
},
4042
},
4143
},
@@ -59,10 +61,12 @@ describe('StateValidationCallbackHandlerService', () => {
5961
it(
6062
'returns callbackContext with validationResult if validationResult is valid',
6163
waitForAsync(() => {
62-
spyOn(stateValidationService, 'getValidatedStateResult').and.returnValue({
63-
idToken: 'idTokenJustForTesting',
64-
authResponseIsValid: true,
65-
} as StateValidationResult);
64+
spyOn(stateValidationService, 'getValidatedStateResult').and.returnValue(
65+
of({
66+
idToken: 'idTokenJustForTesting',
67+
authResponseIsValid: true,
68+
} as StateValidationResult),
69+
);
6670

6771
service.callbackStateValidation({} as CallbackContext, 'configId').subscribe((newCallbackContext) => {
6872
expect(newCallbackContext).toEqual({
@@ -72,36 +76,40 @@ describe('StateValidationCallbackHandlerService', () => {
7276
},
7377
} as CallbackContext);
7478
});
75-
})
79+
}),
7680
);
7781

7882
it(
7983
'logs error in case of an error',
8084
waitForAsync(() => {
81-
spyOn(stateValidationService, 'getValidatedStateResult').and.returnValue({
82-
authResponseIsValid: false,
83-
} as StateValidationResult);
85+
spyOn(stateValidationService, 'getValidatedStateResult').and.returnValue(
86+
of({
87+
authResponseIsValid: false,
88+
} as StateValidationResult),
89+
);
8490

8591
const loggerSpy = spyOn(loggerService, 'logWarning');
8692

8793
service.callbackStateValidation({} as CallbackContext, 'configId').subscribe({
8894
error: (err) => {
8995
expect(loggerSpy).toHaveBeenCalledOnceWith(
9096
'configId',
91-
'authorizedCallback, token(s) validation failed, resetting. Hash: &anyFakeHash'
97+
'authorizedCallback, token(s) validation failed, resetting. Hash: &anyFakeHash',
9298
);
9399
},
94100
});
95-
})
101+
}),
96102
);
97103

98104
it(
99105
'calls resetAuthDataService.resetAuthorizationData and authStateService.updateAndPublishAuthState in case of an error',
100106
waitForAsync(() => {
101-
spyOn(stateValidationService, 'getValidatedStateResult').and.returnValue({
102-
authResponseIsValid: false,
103-
state: ValidationResult.LoginRequired,
104-
} as StateValidationResult);
107+
spyOn(stateValidationService, 'getValidatedStateResult').and.returnValue(
108+
of({
109+
authResponseIsValid: false,
110+
state: ValidationResult.LoginRequired,
111+
} as StateValidationResult),
112+
);
105113

106114
const resetAuthorizationDataSpy = spyOn(resetAuthDataService, 'resetAuthorizationData');
107115
const updateAndPublishAuthStateSpy = spyOn(authStateService, 'updateAndPublishAuthState');
@@ -116,7 +124,7 @@ describe('StateValidationCallbackHandlerService', () => {
116124
});
117125
},
118126
});
119-
})
127+
}),
120128
);
121129
});
122130
});

projects/angular-auth-oidc-client/src/lib/flows/callback-handling/state-validation-callback-handler.service.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { DOCUMENT } from '@angular/common';
22
import { Inject, Injectable } from '@angular/core';
3-
import { Observable, of, throwError } from 'rxjs';
3+
import { Observable, throwError } from 'rxjs';
44
import { AuthStateService } from '../../auth-state/auth-state.service';
55
import { LoggerService } from '../../logging/logger.service';
66
import { StateValidationResult } from '../../validation/state-validation-result';
77
import { StateValidationService } from '../../validation/state-validation.service';
88
import { CallbackContext } from '../callback-context';
99
import { ResetAuthDataService } from '../reset-auth-data.service';
10+
import { map } from 'rxjs/operators';
1011

1112
@Injectable()
1213
export class StateValidationCallbackHandlerService {
@@ -21,21 +22,24 @@ export class StateValidationCallbackHandlerService {
2122
// STEP 4 All flows
2223

2324
callbackStateValidation(callbackContext: CallbackContext, configId: string): Observable<CallbackContext> {
24-
const validationResult = this.stateValidationService.getValidatedStateResult(callbackContext, configId);
25-
callbackContext.validationResult = validationResult;
25+
return this.stateValidationService.getValidatedStateResult(callbackContext, configId).pipe(
26+
map((validationResult: StateValidationResult) => {
27+
callbackContext.validationResult = validationResult;
2628

27-
if (validationResult.authResponseIsValid) {
28-
this.authStateService.setAuthorizationData(validationResult.accessToken, callbackContext.authResult, configId);
29+
if (validationResult.authResponseIsValid) {
30+
this.authStateService.setAuthorizationData(validationResult.accessToken, callbackContext.authResult, configId);
2931

30-
return of(callbackContext);
31-
} else {
32-
const errorMessage = `authorizedCallback, token(s) validation failed, resetting. Hash: ${this.doc.location.hash}`;
33-
this.loggerService.logWarning(configId, errorMessage);
34-
this.resetAuthDataService.resetAuthorizationData(configId);
35-
this.publishUnauthorizedState(callbackContext.validationResult, callbackContext.isRenewProcess);
36-
37-
return throwError(() => new Error(errorMessage));
38-
}
32+
return callbackContext;
33+
} else {
34+
const errorMessage = `authorizedCallback, token(s) validation failed, resetting. Hash: ${this.doc.location.hash}`;
35+
this.loggerService.logWarning(configId, errorMessage);
36+
this.resetAuthDataService.resetAuthorizationData(configId);
37+
this.publishUnauthorizedState(callbackContext.validationResult, callbackContext.isRenewProcess);
38+
39+
throw new Error(errorMessage);
40+
}
41+
})
42+
);
3943
}
4044

4145
private publishUnauthorizedState(stateValidationResult: StateValidationResult, isRenewProcess: boolean): void {

projects/angular-auth-oidc-client/src/lib/iframe/refresh-session-iframe.service.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe('RefreshSessionIframeService ', () => {
3838
it(
3939
'calls sendAuthorizeRequestUsingSilentRenew with created url',
4040
waitForAsync(() => {
41-
spyOn(urlService, 'getRefreshSessionSilentRenewUrl').and.returnValue('a-url');
41+
spyOn(urlService, 'getRefreshSessionSilentRenewUrl').and.returnValue(of('a-url'));
4242
const sendAuthorizeRequestUsingSilentRenewSpy = spyOn(
4343
refreshSessionIframeService as any,
4444
'sendAuthorizeRequestUsingSilentRenew'
@@ -53,7 +53,7 @@ describe('RefreshSessionIframeService ', () => {
5353
it(
5454
'returns correct observable',
5555
waitForAsync(() => {
56-
spyOn(urlService, 'getRefreshSessionSilentRenewUrl').and.returnValue('a-url');
56+
spyOn(urlService, 'getRefreshSessionSilentRenewUrl').and.returnValue(of('a-url'));
5757
const sessionIFrame = document.createElement('iframe');
5858
sessionIFrame.onload = () => {
5959
// contentWindow is set!

projects/angular-auth-oidc-client/src/lib/iframe/refresh-session-iframe.service.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { DOCUMENT } from '@angular/common';
22
import { Inject, Injectable, Renderer2, RendererFactory2 } from '@angular/core';
33
import { Observable } from 'rxjs';
4+
import { switchMap } from 'rxjs/operators';
45
import { LoggerService } from '../logging/logger.service';
56
import { UrlService } from '../utils/url/url.service';
67
import { SilentRenewService } from './silent-renew.service';
@@ -14,16 +15,19 @@ export class RefreshSessionIframeService {
1415
private loggerService: LoggerService,
1516
private urlService: UrlService,
1617
private silentRenewService: SilentRenewService,
17-
rendererFactory: RendererFactory2
18+
rendererFactory: RendererFactory2,
1819
) {
1920
this.renderer = rendererFactory.createRenderer(null, null);
2021
}
2122

2223
refreshSessionWithIframe(configId: string, customParams?: { [key: string]: string | number | boolean }): Observable<boolean> {
2324
this.loggerService.logDebug(configId, 'BEGIN refresh session Authorize Iframe renew');
24-
const url = this.urlService.getRefreshSessionSilentRenewUrl(configId, customParams);
2525

26-
return this.sendAuthorizeRequestUsingSilentRenew(url, configId);
26+
return this.urlService.getRefreshSessionSilentRenewUrl(configId, customParams).pipe(
27+
switchMap((url) => {
28+
return this.sendAuthorizeRequestUsingSilentRenew(url, configId);
29+
}),
30+
);
2731
}
2832

2933
private sendAuthorizeRequestUsingSilentRenew(url: string, configId: string): Observable<boolean> {
@@ -53,13 +57,13 @@ export class RefreshSessionIframeService {
5357
}
5458
});
5559
const renewDestroyHandler = this.renderer.listen('window', 'oidc-silent-renew-message', (e) =>
56-
this.silentRenewService.silentRenewEventHandler(e, configId)
60+
this.silentRenewService.silentRenewEventHandler(e, configId),
5761
);
5862

5963
this.doc.defaultView.dispatchEvent(
6064
new CustomEvent('oidc-silent-renew-init', {
6165
detail: instanceId,
62-
})
66+
}),
6367
);
6468
}
6569
}

0 commit comments

Comments
 (0)