Skip to content

Commit 02cc5fc

Browse files
authored
Merge pull request #1093 from damienbod/damien/dev-params
Support Custom Params for EndSession and RefreshTokens Renew
2 parents b5c1654 + e82f09f commit 02cc5fc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+817
-71
lines changed

.vscode/settings.json

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,27 @@
11
{
2-
"editor.codeActionsOnSave": {
3-
"source.organizeImports": true
4-
},
5-
"editor.formatOnSave": true,
6-
"editor.formatOnPaste": true,
7-
"editor.defaultFormatter": "esbenp.prettier-vscode",
8-
"[typescript]": {
9-
"editor.defaultFormatter": "esbenp.prettier-vscode"
10-
},
11-
"[json]": {
12-
"editor.defaultFormatter": "esbenp.prettier-vscode"
13-
},
14-
"[jsonc]": {
15-
"editor.defaultFormatter": "esbenp.prettier-vscode"
16-
},
17-
"[javascript]": {
18-
"editor.defaultFormatter": "esbenp.prettier-vscode"
19-
},
20-
"[html]": {
21-
"editor.defaultFormatter": "esbenp.prettier-vscode"
22-
},
23-
"[less]": {
24-
"editor.defaultFormatter": "esbenp.prettier-vscode"
25-
},
26-
"cSpell.words": [
27-
"Authorisation",
28-
"autologin",
29-
"azuread",
30-
"jwtkeys",
31-
"oidc",
32-
"openid"
33-
]
2+
"editor.codeActionsOnSave": {
3+
"source.organizeImports": true
4+
},
5+
"editor.formatOnSave": true,
6+
"editor.formatOnPaste": false,
7+
"editor.defaultFormatter": "esbenp.prettier-vscode",
8+
"[typescript]": {
9+
"editor.defaultFormatter": "esbenp.prettier-vscode"
10+
},
11+
"[json]": {
12+
"editor.defaultFormatter": "esbenp.prettier-vscode"
13+
},
14+
"[jsonc]": {
15+
"editor.defaultFormatter": "esbenp.prettier-vscode"
16+
},
17+
"[javascript]": {
18+
"editor.defaultFormatter": "esbenp.prettier-vscode"
19+
},
20+
"[html]": {
21+
"editor.defaultFormatter": "esbenp.prettier-vscode"
22+
},
23+
"[less]": {
24+
"editor.defaultFormatter": "esbenp.prettier-vscode"
25+
},
26+
"cSpell.words": ["Authorisation", "autologin", "azuread", "jwtkeys", "oidc", "openid"]
3427
}

CHANGELOG.md

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

3+
### 2021-05-04 Version 11.6.9
4+
5+
- Support Custom Params for EndSession and RefreshTokens Renew
6+
- [PR](https://github.com/damienbod/angular-auth-oidc-client/pull/1093)
7+
- Added Auth0 example
8+
39
### 2021-05-04 Version 11.6.8
410

511
- bugfix incorrect storage for silent renew, requires Json object

angular.json

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,110 @@
786786
}
787787
}
788788
},
789+
790+
"sample-code-flow-auth0": {
791+
"projectType": "application",
792+
"schematics": {},
793+
"root": "projects/sample-code-flow-auth0",
794+
"sourceRoot": "projects/sample-code-flow-auth0/src",
795+
"prefix": "app",
796+
"architect": {
797+
"build": {
798+
"builder": "@angular-devkit/build-angular:browser",
799+
"options": {
800+
"outputPath": "dist/sample-code-flow-auth0",
801+
"index": "projects/sample-code-flow-auth0/src/index.html",
802+
"main": "projects/sample-code-flow-auth0/src/main.ts",
803+
"polyfills": "projects/sample-code-flow-auth0/src/polyfills.ts",
804+
"tsConfig": "projects/sample-code-flow-auth0/tsconfig.app.json",
805+
"aot": true,
806+
"assets": ["projects/sample-code-flow-auth0/src/favicon.ico", "projects/sample-code-flow-auth0/src/assets"],
807+
"styles": ["projects/sample-code-flow-auth0/src/styles.css"],
808+
"scripts": []
809+
},
810+
"configurations": {
811+
"production": {
812+
"fileReplacements": [
813+
{
814+
"replace": "projects/sample-code-flow-auth0/src/environments/environment.ts",
815+
"with": "projects/sample-code-flow-auth0/src/environments/environment.prod.ts"
816+
}
817+
],
818+
"optimization": true,
819+
"outputHashing": "all",
820+
"sourceMap": false,
821+
"namedChunks": false,
822+
"extractLicenses": true,
823+
"vendorChunk": false,
824+
"buildOptimizer": true,
825+
"budgets": [
826+
{
827+
"type": "initial",
828+
"maximumWarning": "2mb",
829+
"maximumError": "5mb"
830+
},
831+
{
832+
"type": "anyComponentStyle",
833+
"maximumWarning": "6kb",
834+
"maximumError": "10kb"
835+
}
836+
]
837+
}
838+
}
839+
},
840+
"serve": {
841+
"builder": "@angular-devkit/build-angular:dev-server",
842+
"options": {
843+
"browserTarget": "sample-code-flow-auth0:build",
844+
"sslKey": "certs/dev_localhost.key",
845+
"sslCert": "certs/dev_localhost.pem",
846+
"port": 4204
847+
},
848+
"configurations": {
849+
"production": {
850+
"browserTarget": "sample-code-flow-auth0:build:production"
851+
}
852+
}
853+
},
854+
"extract-i18n": {
855+
"builder": "@angular-devkit/build-angular:extract-i18n",
856+
"options": {
857+
"browserTarget": "sample-code-flow-auth0:build"
858+
}
859+
},
860+
"test": {
861+
"builder": "@angular-devkit/build-angular:karma",
862+
"options": {
863+
"main": "projects/sample-code-flow-auth0/src/test.ts",
864+
"polyfills": "projects/sample-code-flow-auth0/src/polyfills.ts",
865+
"tsConfig": "projects/sample-code-flow-auth0/tsconfig.spec.json",
866+
"karmaConfig": "projects/sample-code-flow-auth0/karma.conf.js",
867+
"assets": ["projects/sample-code-flow-auth0/src/favicon.ico", "projects/sample-code-flow-auth0/src/assets"],
868+
"styles": ["projects/sample-code-flow-auth0/src/styles.css"],
869+
"scripts": []
870+
}
871+
},
872+
"lint": {
873+
"builder": "@angular-eslint/builder:lint",
874+
"options": {
875+
"lintFilePatterns": ["projects/sample-code-flow-auth0/**/*.ts", "projects/sample-code-flow-auth0/**/*.html"]
876+
}
877+
},
878+
"e2e": {
879+
"builder": "@angular-devkit/build-angular:protractor",
880+
"options": {
881+
"protractorConfig": "projects/sample-code-flow-auth0/e2e/protractor.conf.js",
882+
"devServerTarget": "sample-code-flow-auth0:serve"
883+
},
884+
"configurations": {
885+
"production": {
886+
"devServerTarget": "sample-code-flow-auth0:serve:production"
887+
}
888+
}
889+
}
890+
}
891+
},
892+
789893
"sample-code-flow-refresh-tokens": {
790894
"projectType": "application",
791895
"schematics": {},

docs/configuration.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,5 @@ In this document are all the values which can be set to configure this library.
4141
| `customTokenParams` | `{ [key: string]: string, number, boolean }` | extra parameters can be added to the token URL request. | No |
4242
| `refreshTokenRetryInSeconds` | `number` | Controls the periodic retry time interval for retrieving new tokens in seconds, default = 3. `silentRenewTimeoutInSeconds` and `tokenRefreshInSeconds` are upper bounds for this value. | No |
4343
| `ngswBypass` | `boolean` | Adds the `ngsw-bypass` param to all requests ([Angular Docu](https://angular.io/guide/service-worker-devops#bypassing-the-service-worker)). | No |
44+
| `customParamsRefreshToken` | `{ [key: string]: string, number, boolean }` | Extra parameters to add to the refresh token request body. | No |
45+
| `customParamsEndSession` | `{ [key: string]: string, number, boolean }` | Extra parameters to add to the endsession request body. | No |

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: 2 additions & 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.8",
11+
"version": "11.6.9",
1212
"scripts": {
1313
"ng": "ng",
1414
"build": "npm run build-lib",
@@ -35,6 +35,7 @@
3535
"start-sample-code-flow-popup": "ng serve sample-code-flow-popup --ssl -o",
3636
"start-sample-code-flow-http-config": "ng serve sample-code-flow-http-config --ssl -o",
3737
"start-sample-code-flow-refresh-tokens": "ng serve sample-code-flow-refresh-tokens --ssl -o",
38+
"start-sample-code-flow-auth0": "ng serve sample-code-flow-auth0 --ssl -o",
3839
"start-sample-code-flow-par": "ng serve sample-code-flow-par --ssl -o",
3940
"start-sample-code-flow-azure-b2c": "ng serve sample-code-flow-azure-b2c --ssl -o",
4041
"start-sample-code-flow-azuread": "ng serve sample-code-flow-azuread --ssl -o",

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.8",
40+
"version": "11.6.9",
4141
"description": "Angular Lib for OpenID Connect & OAuth2",
4242
"schematics": "./schematics/collection.json"
4343
}

projects/angular-auth-oidc-client/src/lib/callback/periodically-token-check.service.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,24 @@ export class PeriodicallyTokenCheckService {
7272

7373
this.flowsDataService.setSilentRenewRunning();
7474

75+
if (this.flowHelper.isCurrentFlowCodeFlowWithRefreshTokens()) {
76+
// Retrieve Dynamically Set Custom Params for refresh body
77+
const customParamsRefresh: { [key: string]: string | number | boolean } = this.storagePersistenceService.read(
78+
'storageCustomParamsRefresh'
79+
);
80+
const { customParamsRefreshToken } = this.configurationProvider.getOpenIDConfiguration();
81+
82+
const mergedParams = { ...customParamsRefresh, ...customParamsRefreshToken };
83+
84+
// Refresh Session using Refresh tokens
85+
return this.refreshSessionRefreshTokenService.refreshSessionWithRefreshTokens(mergedParams);
86+
}
87+
7588
// Retrieve Dynamically Set Custom Params
7689
const customParams: { [key: string]: string | number | boolean } = this.storagePersistenceService.read(
7790
'storageCustomRequestParams'
7891
);
7992

80-
if (this.flowHelper.isCurrentFlowCodeFlowWithRefreshTokens()) {
81-
// Refresh Session using Refresh tokens
82-
return this.refreshSessionRefreshTokenService.refreshSessionWithRefreshTokens(customParams);
83-
}
84-
8593
return this.refreshSessionIframeService.refreshSessionWithIframe(customParams);
8694
})
8795
);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { Injectable } from '@angular/core';
22
import { Observable, throwError } from 'rxjs';
33
import { catchError } from 'rxjs/operators';
4+
import { CallbackContext } from '../flows/callback-context';
45
import { FlowsService } from '../flows/flows.service';
56
import { ResetAuthDataService } from '../flows/reset-auth-data.service';
67
import { LoggerService } from '../logging/logger.service';
78
import { IntervallService } from './intervall.service';
8-
import { CallbackContext } from '../flows/callback-context';
99

1010
@Injectable({ providedIn: 'root' })
1111
export class RefreshSessionRefreshTokenService {
@@ -16,10 +16,10 @@ export class RefreshSessionRefreshTokenService {
1616
private intervalService: IntervallService
1717
) {}
1818

19-
refreshSessionWithRefreshTokens(customParams?: { [key: string]: string | number | boolean }): Observable<CallbackContext> {
19+
refreshSessionWithRefreshTokens(customParamsRefresh?: { [key: string]: string | number | boolean }): Observable<CallbackContext> {
2020
this.loggerService.logDebug('BEGIN refresh session Authorize');
2121

22-
return this.flowsService.processRefreshToken(customParams).pipe(
22+
return this.flowsService.processRefreshToken(customParamsRefresh).pipe(
2323
catchError((error) => {
2424
this.intervalService.stopPeriodicallTokenCheck();
2525
this.resetAuthDataService.resetAuthorizationData();

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import { map, mergeMap, retryWhen, switchMap, take, timeout } from 'rxjs/operato
44
import { AuthStateService } from '../authState/auth-state.service';
55
import { AuthWellKnownService } from '../config/auth-well-known.service';
66
import { ConfigurationProvider } from '../config/config.provider';
7+
import { CallbackContext } from '../flows/callback-context';
78
import { FlowsDataService } from '../flows/flows-data.service';
89
import { RefreshSessionIframeService } from '../iframe/refresh-session-iframe.service';
910
import { SilentRenewService } from '../iframe/silent-renew.service';
1011
import { LoggerService } from '../logging/logger.service';
12+
import { TokenResponse } from '../tokens/token-response';
1113
import { FlowHelper } from '../utils/flowHelper/flow-helper.service';
1214
import { RefreshSessionRefreshTokenService } from './refresh-session-refresh-token.service';
13-
import { TokenResponse } from '../tokens/token-response';
14-
import { CallbackContext } from '../flows/callback-context';
1515

1616
export const MAX_RETRY_ATTEMPTS = 3;
1717
@Injectable({ providedIn: 'root' })
@@ -28,9 +28,11 @@ export class RefreshSessionService {
2828
private refreshSessionRefreshTokenService: RefreshSessionRefreshTokenService
2929
) {}
3030

31-
forceRefreshSession(customParams?: { [key: string]: string | number | boolean }): Observable<TokenResponse | null> {
31+
forceRefreshSession(extraCustomParams?: { [key: string]: string | number | boolean }): Observable<TokenResponse | null> {
3232
if (this.flowHelper.isCurrentFlowCodeFlowWithRefreshTokens()) {
33-
return this.startRefreshSession(customParams).pipe(
33+
const { customParamsRefreshToken } = this.configurationProvider.getOpenIDConfiguration();
34+
const mergedParams = { ...extraCustomParams, ...customParamsRefreshToken };
35+
return this.startRefreshSession(mergedParams).pipe(
3436
map(() => {
3537
const isAuthenticated = this.authStateService.areAuthStorageTokensValid();
3638
if (isAuthenticated) {
@@ -49,7 +51,7 @@ export class RefreshSessionService {
4951
const timeOutTime = silentRenewTimeoutInSeconds * 1000;
5052

5153
return forkJoin([
52-
this.startRefreshSession(customParams),
54+
this.startRefreshSession(extraCustomParams),
5355
this.silentRenewService.refreshSessionWithIFrameCompleted$.pipe(take(1)),
5456
]).pipe(
5557
timeout(timeOutTime),
@@ -68,7 +70,9 @@ export class RefreshSessionService {
6870
);
6971
}
7072

71-
private startRefreshSession(customParams?: { [key: string]: string | number | boolean }): Observable<boolean | CallbackContext | null> {
73+
private startRefreshSession(extraCustomParams?: {
74+
[key: string]: string | number | boolean;
75+
}): Observable<boolean | CallbackContext | null> {
7276
const isSilentRenewRunning = this.flowsDataService.isSilentRenewRunning();
7377
this.loggerService.logDebug(`Checking: silentRenewRunning: ${isSilentRenewRunning}`);
7478
const shouldBeExecuted = !isSilentRenewRunning;
@@ -90,10 +94,10 @@ export class RefreshSessionService {
9094

9195
if (this.flowHelper.isCurrentFlowCodeFlowWithRefreshTokens()) {
9296
// Refresh Session using Refresh tokens
93-
return this.refreshSessionRefreshTokenService.refreshSessionWithRefreshTokens(customParams);
97+
return this.refreshSessionRefreshTokenService.refreshSessionWithRefreshTokens(extraCustomParams);
9498
}
9599

96-
return this.refreshSessionIframeService.refreshSessionWithIframe(customParams);
100+
return this.refreshSessionIframeService.refreshSessionWithIframe(extraCustomParams);
97101
})
98102
);
99103
}

0 commit comments

Comments
 (0)