Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Token refresh interval configuration #900

Merged
merged 6 commits into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Angular Lib for OpenID Connect/OAuth2 Changelog

### 2020-11-20 Version 11.2.3

- Added config tokenRefreshInSeconds which controls the time interval to run the startTokenValidationPeriodically
- [PR](https://github.com/damienbod/angular-auth-oidc-client/pull/900)

### 2020-11-13 Version 11.2.2

- Multiple tabs don't receive any event when session state becomes blank
Expand Down
1 change: 1 addition & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ In this document are all the values which can be set to configure this library.
| `customParams` | `{ [key: string]: string, number, boolean }` | extra parameters can be added to the authorization URL request. | No |
| `disableRefreshIdTokenAuthTimeValidation` | `boolean` | disables the auth_time validation for id_tokens in a refresh due to Azure incorrect implementation | No |
| `eagerLoadAuthWellKnownEndpoints` | `boolean` | Tells if the AuthWellKnownEndpoints should be loaded on start or when the user calls the `authorize` method | No |
| `tokenRefreshInSeconds` | `number` | Controls the periodic check time interval in seconds, default = 3 | No |
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"bugs": {
"url": "https://github.com/damienbod/angular-auth-oidc-client/issues"
},
"version": "11.2.2",
"version": "11.2.3",
"scripts": {
"ng": "ng",
"build": "npm run build-lib",
Expand Down
2 changes: 1 addition & 1 deletion projects/angular-auth-oidc-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@
"authorization"
],
"license": "MIT",
"version": "11.2.2",
"version": "11.2.3",
"description": "Angular Lib for OpenID Connect & OAuth2"
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class PeriodicallyTokenCheckService {
)
.subscribe(
() => {
this.loggerService.logDebug('silent renew finished!');
this.loggerService.logDebug('silent renew, periodic check finished!');
if (this.flowHelper.isCurrentFlowCodeFlowWithRefeshTokens()) {
this.flowsDataService.resetSilentRenewRunning();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ describe('ConfigurationProviderTests', () => {
customParams: {},
eagerLoadAuthWellKnownEndpoints: true,
disableRefreshIdTokenAuthTimeValidation: false,
tokenRefreshInSeconds: 3,
};

configurationProvider.setConfig({ stsServer: 'https://please_set' });
Expand Down Expand Up @@ -114,6 +115,7 @@ describe('ConfigurationProviderTests', () => {
customParams: {},
eagerLoadAuthWellKnownEndpoints: true,
disableRefreshIdTokenAuthTimeValidation: false,
tokenRefreshInSeconds: 3,
};

configurationProvider.setConfig(config);
Expand Down Expand Up @@ -158,6 +160,7 @@ describe('ConfigurationProviderTests', () => {
customParams: {},
eagerLoadAuthWellKnownEndpoints: true,
disableRefreshIdTokenAuthTimeValidation: false,
tokenRefreshInSeconds: 3,
};

spyOnProperty(platformProvider, 'isBrowser').and.returnValue(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ export const DEFAULT_CONFIG: OpenIdConfiguration = {
customParams: {},
eagerLoadAuthWellKnownEndpoints: true,
disableRefreshIdTokenAuthTimeValidation: false,
tokenRefreshInSeconds: 3,
};
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ export interface OpenIdConfiguration {

// Azure B2C have implemented this incorrectly. Add support for to disable this until fixed.
disableRefreshIdTokenAuthTimeValidation?: boolean;
tokenRefreshInSeconds?: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -296,15 +296,19 @@ describe('OidcSecurityService', () => {
}));

it('if authenticated callbackService startTokenValidationPeriodically', async(() => {
const config = {
stsServer: 'stsServer',
tokenRefreshInSeconds: 7,
};
spyOn(configurationProvider, 'hasValidConfig').and.returnValue(true);
spyOnProperty(configurationProvider, 'openIDConfiguration', 'get').and.returnValue('stsServer');
spyOnProperty(configurationProvider, 'openIDConfiguration', 'get').and.returnValue(config);
spyOn(callBackService, 'handleCallbackAndFireEvents').and.returnValue(of(null));
spyOn(authStateService, 'areAuthStorageTokensValid').and.returnValue(true);

const spy = spyOn(periodicallyTokenCheckService, 'startTokenValidationPeriodically');

oidcSecurityService.checkAuth().subscribe((result) => {
expect(spy).toHaveBeenCalledWith(3);
expect(spy).toHaveBeenCalledWith(7);
});
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import { TokenHelperService } from './utils/tokenHelper/oidc-token-helper.servic

@Injectable()
export class OidcSecurityService {
private TOKEN_REFRESH_INTERVALL_IN_SECONDS = 3;

get configuration(): PublicConfiguration {
return {
configuration: this.configurationProvider.openIDConfiguration,
Expand Down Expand Up @@ -123,7 +121,7 @@ export class OidcSecurityService {
this.checkSessionService.start();
}

this.periodicallyTokenCheckService.startTokenValidationPeriodically(this.TOKEN_REFRESH_INTERVALL_IN_SECONDS);
this.periodicallyTokenCheckService.startTokenValidationPeriodically(this.configuration.configuration.tokenRefreshInSeconds);

if (this.silentRenewService.isSilentRenewConfigured()) {
this.silentRenewService.getOrCreateIframe();
Expand Down