Skip to content

Commit 9a39fa3

Browse files
authored
Merge pull request #1128 from damienbod/fabiangosebrink/silent-renew-does-not-always-start
Fabiangosebrink/silent renew does not always start
2 parents aa47dda + 3014c17 commit 9a39fa3

File tree

9 files changed

+65
-12
lines changed

9 files changed

+65
-12
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## Angular Lib for OpenID Connect/OAuth2 Changelog
22

3+
### 2021-06-12 Version 11.6.11
4+
5+
- Silent renew does not always start
6+
- [PR](https://github.com/damienbod/angular-auth-oidc-client/pull/1128)
7+
38
### 2021-05-28 Version 11.6.10
49

510
- AutoLoginGuard appears to cause some sort of infinite loop.

package-lock.json

Lines changed: 2 additions & 2 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
@@ -8,7 +8,7 @@
88
"bugs": {
99
"url": "https://github.com/damienbod/angular-auth-oidc-client/issues"
1010
},
11-
"version": "11.6.10",
11+
"version": "11.6.11",
1212
"scripts": {
1313
"ng": "ng",
1414
"build": "npm run build-lib",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"authorization"
3838
],
3939
"license": "MIT",
40-
"version": "11.6.10",
40+
"version": "11.6.11",
4141
"description": "Angular Lib for OpenID Connect & OAuth2",
4242
"schematics": "./schematics/collection.json"
4343
}

projects/angular-auth-oidc-client/src/lib/auto-login/auto-login.guard.spec.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ describe(`AutoLoginGuard`, () => {
5656
it(
5757
'should call checkAuth() if not authenticated already',
5858
waitForAsync(() => {
59+
spyOn(authStateService, 'areAuthStorageTokensValid').and.returnValue(false);
5960
const checkAuthServiceSpy = spyOn(checkAuthService, 'checkAuth').and.returnValue(of(null));
6061

6162
autoLoginGuard.canActivate(null, { url: 'some-url1' } as RouterStateSnapshot).subscribe(() => {
@@ -67,8 +68,8 @@ describe(`AutoLoginGuard`, () => {
6768
it(
6869
'should NOT call checkAuth() if authenticated already',
6970
waitForAsync(() => {
71+
spyOn(authStateService, 'areAuthStorageTokensValid').and.returnValue(true);
7072
const checkAuthServiceSpy = spyOn(checkAuthService, 'checkAuth').and.returnValue(of(null));
71-
spyOnProperty(authStateService, 'authorized$', 'get').and.returnValue(of(true));
7273

7374
autoLoginGuard.canActivate(null, { url: 'some-url2' } as RouterStateSnapshot).subscribe(() => {
7475
expect(checkAuthServiceSpy).not.toHaveBeenCalled();
@@ -79,6 +80,7 @@ describe(`AutoLoginGuard`, () => {
7980
it(
8081
'should call loginService.login() when not authorized',
8182
waitForAsync(() => {
83+
spyOn(authStateService, 'areAuthStorageTokensValid').and.returnValue(false);
8284
spyOn(checkAuthService, 'checkAuth').and.returnValue(of(null));
8385
const loginSpy = spyOn(loginService, 'login');
8486

@@ -91,6 +93,7 @@ describe(`AutoLoginGuard`, () => {
9193
it(
9294
'should return false when not authorized',
9395
waitForAsync(() => {
96+
spyOn(authStateService, 'areAuthStorageTokensValid').and.returnValue(false);
9497
spyOn(checkAuthService, 'checkAuth').and.returnValue(of(null));
9598

9699
autoLoginGuard.canActivate(null, { url: 'some-url4' } as RouterStateSnapshot).subscribe((result) => {
@@ -102,6 +105,7 @@ describe(`AutoLoginGuard`, () => {
102105
it(
103106
'if no route is stored, setItem on localStorage is called',
104107
waitForAsync(() => {
108+
spyOn(authStateService, 'areAuthStorageTokensValid').and.returnValue(false);
105109
spyOn(checkAuthService, 'checkAuth').and.returnValue(of(null));
106110
const localStorageSpy = spyOn(localStorage, 'setItem');
107111

@@ -127,6 +131,7 @@ describe(`AutoLoginGuard`, () => {
127131
it(
128132
'if authorized and stored route exists: remove item, navigate to route and return true',
129133
waitForAsync(() => {
134+
spyOn(authStateService, 'areAuthStorageTokensValid').and.returnValue(false);
130135
spyOn(checkAuthService, 'checkAuth').and.returnValue(of(true));
131136
spyOn(localStorage, 'getItem').and.returnValue('stored-route');
132137
const localStorageSpy = spyOn(localStorage, 'removeItem');
@@ -147,6 +152,7 @@ describe(`AutoLoginGuard`, () => {
147152
it(
148153
'should call checkAuth() if not authenticated already',
149154
waitForAsync(() => {
155+
spyOn(authStateService, 'areAuthStorageTokensValid').and.returnValue(false);
150156
const checkAuthServiceSpy = spyOn(checkAuthService, 'checkAuth').and.returnValue(of(null));
151157

152158
autoLoginGuard.canLoad(null, []).subscribe(() => {
@@ -159,7 +165,7 @@ describe(`AutoLoginGuard`, () => {
159165
'should NOT call checkAuth() if authenticated already',
160166
waitForAsync(() => {
161167
const checkAuthServiceSpy = spyOn(checkAuthService, 'checkAuth').and.returnValue(of(null));
162-
spyOnProperty(authStateService, 'authorized$', 'get').and.returnValue(of(true));
168+
spyOn(authStateService, 'areAuthStorageTokensValid').and.returnValue(true);
163169

164170
autoLoginGuard.canLoad(null, []).subscribe(() => {
165171
expect(checkAuthServiceSpy).not.toHaveBeenCalled();
@@ -170,6 +176,7 @@ describe(`AutoLoginGuard`, () => {
170176
it(
171177
'should call loginService.login() when not authorized',
172178
waitForAsync(() => {
179+
spyOn(authStateService, 'areAuthStorageTokensValid').and.returnValue(false);
173180
spyOn(checkAuthService, 'checkAuth').and.returnValue(of(null));
174181
const loginSpy = spyOn(loginService, 'login');
175182

@@ -182,6 +189,7 @@ describe(`AutoLoginGuard`, () => {
182189
it(
183190
'should return false when not authorized',
184191
waitForAsync(() => {
192+
spyOn(authStateService, 'areAuthStorageTokensValid').and.returnValue(false);
185193
spyOn(checkAuthService, 'checkAuth').and.returnValue(of(null));
186194

187195
autoLoginGuard.canLoad(null, []).subscribe((result) => {
@@ -193,6 +201,7 @@ describe(`AutoLoginGuard`, () => {
193201
it(
194202
'if no route is stored, setItem on localStorage is called',
195203
waitForAsync(() => {
204+
spyOn(authStateService, 'areAuthStorageTokensValid').and.returnValue(false);
196205
spyOn(checkAuthService, 'checkAuth').and.returnValue(of(null));
197206
const localStorageSpy = spyOn(localStorage, 'setItem');
198207

@@ -205,6 +214,7 @@ describe(`AutoLoginGuard`, () => {
205214
it(
206215
'if no route is stored, setItem on localStorage is called, multiple params',
207216
waitForAsync(() => {
217+
spyOn(authStateService, 'areAuthStorageTokensValid').and.returnValue(false);
208218
spyOn(checkAuthService, 'checkAuth').and.returnValue(of(null));
209219
const localStorageSpy = spyOn(localStorage, 'setItem');
210220

@@ -232,6 +242,7 @@ describe(`AutoLoginGuard`, () => {
232242
it(
233243
'if authorized and stored route exists: remove item, navigate to route and return true',
234244
waitForAsync(() => {
245+
spyOn(authStateService, 'areAuthStorageTokensValid').and.returnValue(false);
235246
spyOn(checkAuthService, 'checkAuth').and.returnValue(of(true));
236247
spyOn(localStorage, 'getItem').and.returnValue('stored-route');
237248
const localStorageSpy = spyOn(localStorage, 'removeItem');

projects/angular-auth-oidc-client/src/lib/auto-login/auto-login.guard.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Injectable } from '@angular/core';
22
import { ActivatedRouteSnapshot, CanActivate, CanLoad, Route, Router, RouterStateSnapshot, UrlSegment } from '@angular/router';
33
import { Observable, of } from 'rxjs';
4-
import { concatMap, map } from 'rxjs/operators';
4+
import { map } from 'rxjs/operators';
55
import { AuthStateService } from '../authState/auth-state.service';
66
import { AutoLoginService } from '../auto-login/auto-login-service';
77
import { CheckAuthService } from '../check-auth.service';
@@ -28,9 +28,13 @@ export class AutoLoginGuard implements CanActivate, CanLoad {
2828
}
2929

3030
private checkAuth(url: string) {
31-
return this.authStateService.authorized$.pipe(
32-
concatMap((isAuthenticatedAlready) => (isAuthenticatedAlready ? of(isAuthenticatedAlready) : this.checkAuthService.checkAuth())),
31+
const isAuthenticated = this.authStateService.areAuthStorageTokensValid();
3332

33+
if (isAuthenticated) {
34+
return of(true);
35+
}
36+
37+
return this.checkAuthService.checkAuth().pipe(
3438
map((isAuthorized) => {
3539
const storedRoute = this.autoLoginService.getStoredRedirectRoute();
3640

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { TestBed, waitForAsync } from '@angular/core/testing';
22
import { of } from 'rxjs';
3+
import { skip } from 'rxjs/operators';
34
import { ConfigurationProvider } from '../config/config.provider';
45
import { LoggerService } from '../logging/logger.service';
56
import { LoggerServiceMock } from '../logging/logger.service-mock';
67
import { OidcSecurityService } from '../oidc.security.service';
78
import { PublicEventsService } from '../public-events/public-events.service';
89
import { AbstractSecurityStorage } from '../storage/abstract-security-storage';
910
import { BrowserStorageMock } from '../storage/browser-storage.service-mock';
10-
import { StoragePersistenceService } from '../storage/storage-persistence.service';
1111
import { StoragePersistenceServiceMock } from '../storage/storage-persistence-service-mock.service';
12+
import { StoragePersistenceService } from '../storage/storage-persistence.service';
1213
import { PlatformProvider } from '../utils/platform-provider/platform.provider';
1314
import { PlatformProviderMock } from '../utils/platform-provider/platform.provider-mock';
1415
import { CheckSessionService } from './check-session.service';
@@ -266,4 +267,36 @@ describe('SecurityCheckSessionTests', () => {
266267
})
267268
);
268269
});
270+
271+
describe('isCheckSessionConfigured', () => {
272+
it('returns true if startCheckSession on config is true', () => {
273+
spyOn(configurationProvider, 'getOpenIDConfiguration').and.returnValue({ startCheckSession: true });
274+
275+
const result = checkSessionService.isCheckSessionConfigured();
276+
277+
expect(result).toBe(true);
278+
});
279+
280+
it('returns true if startCheckSession on config is true', () => {
281+
spyOn(configurationProvider, 'getOpenIDConfiguration').and.returnValue({ startCheckSession: false });
282+
283+
const result = checkSessionService.isCheckSessionConfigured();
284+
285+
expect(result).toBe(false);
286+
});
287+
});
288+
289+
describe('checkSessionChanged$', () => {
290+
it(
291+
'emits when internal event is thrown',
292+
waitForAsync(() => {
293+
checkSessionService.checkSessionChanged$.pipe(skip(1)).subscribe((result) => {
294+
expect(result).toBe(true);
295+
});
296+
297+
const serviceAsAny = checkSessionService as any;
298+
serviceAsAny.checkSessionChangedInternal$.next(true);
299+
})
300+
);
301+
});
269302
});

projects/schematics/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "schematics",
3-
"version": "11.6.10",
3+
"version": "11.6.11",
44
"description": "A schematic for the Angular Lib for OpenID Connect & OAuth2",
55
"scripts": {
66
"build": "tsc -p tsconfig.json",

projects/schematics/src/ng-add/actions/add-dependencies.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { addPackageJsonDependency, NodeDependency, NodeDependencyType } from '@s
44
const dependenciesToAdd = [
55
{
66
name: 'angular-auth-oidc-client',
7-
version: '11.6.10',
7+
version: '11.6.11',
88
},
99
];
1010

0 commit comments

Comments
 (0)