Skip to content

Commit 8c9bd9c

Browse files
authored
Merge pull request #1165 from damienbod/fabiangosebrink/Only-one-returntype-(object)-when-subscribing-to-isAuthenticated-and-userdata-to-avoid-confusion-
Fabiangosebrink/only one returntype (object) when subscribing to is authenticated and userdata to avoid confusion
2 parents 9cf4ce4 + 8b35540 commit 8c9bd9c

File tree

45 files changed

+480
-240
lines changed

Some content is hidden

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

45 files changed

+480
-240
lines changed

docs/site/angular-auth-oidc-client/docs/documentation/features.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ Currently the events
1414
```ts
1515
{
1616
ConfigLoaded,
17+
ConfigLoadingFailed,
1718
CheckSessionReceived,
1819
UserDataChanged,
19-
NewAuthorizationResult,
20+
NewAuthenticationResult,
2021
TokenExpired,
2122
IdTokenExpired,
23+
SilentRenewStarted,
2224
}
2325
```
2426

docs/site/angular-auth-oidc-client/docs/documentation/guards.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ export class AuthorizationGuard implements CanActivate {
2222

2323
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {
2424
return this.oidcSecurityService.isAuthenticated$.pipe(
25-
map((isAuthorized: boolean) => {
26-
console.log('AuthorizationGuard, canActivate isAuthorized: ' + isAuthorized);
25+
map(({ isAuthenticated }) => {
26+
console.log('AuthorizationGuard, canActivate isAuthenticated: ' + isAuthenticated);
2727

28-
if (!isAuthorized) {
28+
if (!isAuthenticated) {
2929
this.router.navigateByUrl('/unauthorized');
3030
return false;
3131
}

docs/site/angular-auth-oidc-client/docs/documentation/public-api.md

+102-41
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,23 @@ The most public accessible observables, properties and methods are placed in the
99

1010
## userData$
1111

12-
The `userData$` observable provides the information about the user after he has logged in. In case you are running with one configuration it returns the user data as an object depending on what you get back from the secure token server as user data.
13-
In case you have multiple configs running it returns a `ConfigUserDataResult[]` which holds the `configId` as well as the `userData` in an array.
12+
The `userData$` observable provides the information about the user after he has logged in. It returns an `UserDataResult` in the following form.
13+
14+
```ts
15+
export interface UserDataResult {
16+
userData: any;
17+
allUserData: ConfigUserDataResult[];
18+
}
19+
20+
export interface ConfigUserDataResult {
21+
configId: string;
22+
userData: any;
23+
}
24+
```
25+
26+
In case you are running with one configuration the `ConfigUserDataResult` contains the user data in the `userData` property and the `ConfigUserData[]` returns the same user data with the `configId` filled in case you need it.
27+
28+
In case you are running with multiple configs the `ConfigUserDataResult`s `userData` property is set to `null` and you find your user data per config in the `ConfigUserData[]`.
1429

1530
Example:
1631

@@ -22,68 +37,114 @@ Single Config:
2237

2338
```json
2439
{
25-
"sub": "...",
26-
"preferred_username": "john@doe.org",
27-
"name": "john@doe.org",
28-
"email": "john@doe.org",
29-
"email_verified": false,
30-
"given_name": "john@doe.org",
31-
"role": "user",
32-
"amr": "pwd"
40+
"userData": {
41+
"sub": "...",
42+
"preferred_username": "john@doe.org",
43+
"name": "john@doe.org",
44+
"email": "john@doe.org",
45+
"email_verified": false,
46+
"given_name": "john@doe.org",
47+
"role": "user",
48+
"amr": "pwd"
49+
},
50+
"allUserData": [
51+
{
52+
"configId": "configId",
53+
"userData": {
54+
"sub": "...",
55+
"preferred_username": "john@doe.org",
56+
"name": "john@doe.org",
57+
"email": "john@doe.org",
58+
"email_verified": false,
59+
"given_name": "john@doe.org",
60+
"role": "user",
61+
"amr": "pwd"
62+
}
63+
}
64+
]
3365
}
3466
```
3567

3668
Multiple Configs:
3769

3870
```json
39-
[
40-
{
41-
"configId": "...",
42-
"userData": {
43-
"sub": "...",
44-
"preferred_username": "john@doe.org",
45-
"name": "john@doe.org",
46-
"email": "john@doe.org",
47-
"email_verified": false,
48-
"given_name": "john@doe.org",
49-
"role": "user",
50-
"amr": "pwd"
71+
{
72+
"userData": null,
73+
"allUserData": [
74+
{
75+
"configId": "configId1",
76+
"userData": {
77+
"sub": "...",
78+
"preferred_username": "john@doe.org",
79+
"name": "john@doe.org",
80+
"email": "john@doe.org",
81+
"email_verified": false,
82+
"given_name": "john@doe.org",
83+
"role": "user",
84+
"amr": "pwd"
85+
}
86+
},
87+
{
88+
"configId": "configId2",
89+
"userData": {
90+
"sub": "...",
91+
"preferred_username": "john@doe.org",
92+
"name": "john@doe.org",
93+
"email": "john@doe.org",
94+
"email_verified": false,
95+
"given_name": "john@doe.org",
96+
"role": "user",
97+
"amr": "pwd"
98+
}
5199
}
52-
},
53-
{
54-
"configId": "...",
55-
"userData": { ... }
56-
}
57-
]
100+
]
101+
}
58102
```
59103

60104
## isAuthenticated$
61105

62-
This property returns an `Observable<boolean>` to receive authenticated events, either true or false if you run in a single config. If you run with multiple configs it returns an `ConfigAuthenticatedResult[]` holding the `configId` as well as a boolean to tell you if you are authenticated or not.
106+
This property returns an `Observable<AuthenticatedResult>`. This object is filled depending on with how many configurations you run. The `AuthenticatedResult` is built as following:
63107

64108
```ts
65-
this.isAuthenticated$ = this.oidcSecurityService.isAuthenticated$; // true/false or...
109+
export interface AuthenticatedResult {
110+
isAuthenticated: boolean;
111+
112+
allConfigsAuthenticated: ConfigAuthenticatedResult[];
113+
}
114+
115+
export interface ConfigAuthenticatedResult {
116+
configId: string;
117+
isAuthenticated: boolean;
118+
}
119+
```
120+
121+
In case you have a single config the `isAuthenticated` on the `AuthenticatedResult` tells you if you are authenticated or not. The `ConfigAuthenticatedResult[]` contains the single config result with it's `configId` and again if this config is authenticated or not.
122+
123+
In case you have multiple configs the `isAuthenticated` on the `AuthenticatedResult` tells you if all configs are authenticated (`true`) or not (`false`). The `ConfigAuthenticatedResult[]` contains the single config results with it's `configId` and again if this config is authenticated or not.
124+
125+
```ts
126+
this.isAuthenticated$ = this.oidcSecurityService.isAuthenticated$;
66127
```
67128

68129
Single Config
69130

70131
```json
71-
true / false;
132+
{
133+
"isAuthenticated": true,
134+
"allConfigsAuthenticated": [{ "configId": "configId1", "isAuthenticated": true }]
135+
}
72136
```
73137

74138
Multiple Configs
75139

76140
```json
77-
[
78-
{
79-
"configId": "...",
80-
"isAuthenticated": true
81-
},
82-
{
83-
"configId": "...",
84-
"isAuthenticated": false
85-
}
86-
]
141+
{
142+
"isAuthenticated": false,
143+
"allConfigsAuthenticated": [
144+
{ "configId": "configId1", "isAuthenticated": true },
145+
{ "configId": "configId2", "isAuthenticated": false }
146+
]
147+
}
87148
```
88149

89150
## checkSessionChanged$

docs/site/angular-auth-oidc-client/docs/migrations/v11-to-v12.md

+31-17
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ New:
355355
this.oidcSecurityService.checkAuth().subscribe(({ isAuthenticated }) => {});
356356
```
357357

358-
### `isAuthenticated$` returning `boolean | ConfigAuthenticatedResult[]` instead of `boolean` only
358+
### `isAuthenticated$` returning `AuthenticatedResult` instead of `boolean` only
359359

360360
Old:
361361

@@ -365,19 +365,11 @@ this.oidcSecurityService.isAuthenticated$.subscribe((isAuthenticated) => {});
365365

366366
New:
367367

368-
Single Config:
369-
370-
```ts
371-
this.oidcSecurityService.isAuthenticated$.subscribe((isAuthenticated: boolean) => {});
372-
```
373-
374-
Multiple Configs:
375-
376368
```ts
377-
this.oidcSecurityService.isAuthenticated$.subscribe((isAuthenticated: ConfigAuthenticatedResult[]) => {});
369+
this.oidcSecurityService.isAuthenticated$.subscribe(({ isAuthenticated, allConfigsAuthenticated }) => {});
378370
```
379371

380-
### `userData$` returning `ConfigUserDataResult[] | any` instead of `any` only
372+
### `userData$` returning `UserDataResult` instead of `any` only
381373

382374
Old:
383375

@@ -390,13 +382,13 @@ New:
390382
Single Config:
391383

392384
```ts
393-
this.oidcSecurityService.userData$.subscribe((userData: any) => {});
385+
this.oidcSecurityService.userData$.subscribe(({ userData }) => {});
394386
```
395387

396388
Multiple Configs:
397389

398390
```ts
399-
this.oidcSecurityService.userData$.subscribe((userData: ConfigUserDataResult[]) => {});
391+
this.oidcSecurityService.userData$.subscribe(({ allUserData }) => {});
400392
```
401393

402394
### `authorize(...)` has new `configId` as first parameter
@@ -462,7 +454,7 @@ const configIdOrNull = ./*...*/;
462454
this.oidcSecurityService.logoff(configIdOrNull, authOptions)
463455
```
464456

465-
## Interface `AuthorizationResult` changed and renamed to `AuthenticatedResult`
457+
## Interface `AuthorizationResult` changed and renamed to `AuthStateResult`
466458

467459
The old interface `AuthorizationResult` had the following structure:
468460

@@ -498,7 +490,7 @@ this.eventService
498490
New
499491

500492
```ts
501-
export interface AuthenticatedResult {
493+
export interface AuthStateResult {
502494
isAuthenticated: boolean;
503495
validationResult: ValidationResult;
504496
isRenewProcess: boolean;
@@ -508,12 +500,34 @@ export interface AuthenticatedResult {
508500
```ts
509501
this.eventService
510502
.registerForEvents()
511-
.pipe(filter((notification) => notification.type === EventTypes.NewAuthorizationResult))
512-
.subscribe((result: OidcClientNotification<AuthenticatedResult>) => {
503+
.pipe(filter((notification) => notification.type === EventTypes.NewAuthenticationResult))
504+
.subscribe((result: OidcClientNotification<AuthStateResult>) => {
513505
console.log('isAuthenticated', result.isAuthenticated);
514506
});
515507
```
516508

509+
## `NewAuthorizationResult` was renamed to `NewAuthenticationResult`
510+
511+
The event has changed from `NewAuthorizationResult` to `NewAuthenticationResult`
512+
513+
Old:
514+
515+
```ts
516+
this.eventService
517+
.registerForEvents()
518+
.pipe(filter((notification) => notification.type === EventTypes.NewAuthorizationResult))
519+
.subscribe((result: OidcClientNotification<AuthorizationResult>) => {});
520+
```
521+
522+
New:
523+
524+
```ts
525+
this.eventService
526+
.registerForEvents()
527+
.pipe(filter((notification) => notification.type === EventTypes.NewAuthenticationResult))
528+
.subscribe((result: OidcClientNotification<AuthStateResult>) => {});
529+
```
530+
517531
## `AutoLoginGuard` --> `AutoLoginAllRoutesGuard` and `AutoLoginPartialRoutesGuard`
518532

519533
Due to a lot of feedback about the `AutoLoginGuard` and usage we did not expect in that way we decided to give the `AuthGuard` a brush and divided it into a `AutoLoginAllRoutesGuard` when you want to secure your complete app and an `AutoLoginPartialRoutesGuard` if some of your routes are publicly accessible.

projects/angular-auth-oidc-client/src/lib/angular-auth-oidc-client.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
export * from './auth-options';
44
export * from './auth.module';
55
export * from './authState/auth-result';
6+
export * from './authState/auth-state';
67
export * from './auto-login/auto-login-all-routes.guard';
78
export * from './auto-login/auto-login-partial-routes.guard';
89
export * from './config/auth-well-known/auth-well-known-endpoints';
@@ -17,6 +18,7 @@ export * from './public-events/event-types';
1718
export * from './public-events/notification';
1819
export * from './public-events/public-events.service';
1920
export * from './storage/abstract-security-storage';
21+
export * from './userData/userdata-result';
2022
export * from './utils/tokenHelper/token-helper.service';
2123
export * from './validation/jwtkeys';
2224
export * from './validation/state-validation-result';

projects/angular-auth-oidc-client/src/lib/authState/auth-result.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import { ValidationResult } from '../validation/validation-result';
2-
31
export interface AuthenticatedResult {
42
isAuthenticated: boolean;
5-
validationResult: ValidationResult;
6-
isRenewProcess: boolean;
3+
4+
allConfigsAuthenticated: ConfigAuthenticatedResult[];
75
}
86

97
export interface ConfigAuthenticatedResult {

0 commit comments

Comments
 (0)