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

Fabiangosebrink/remove app initializer #1307

Merged
merged 72 commits into from
Dec 20, 2021
Merged
Show file tree
Hide file tree
Changes from 70 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
c6f81a8
first shot
FabianGosebrink Nov 21, 2021
92b480d
Merge branch 'main' into fabiangosebrink/remove-app-initializer
FabianGosebrink Nov 21, 2021
f288cd0
moved a little bit around
FabianGosebrink Nov 21, 2021
85dea39
Merge branch 'main' into fabiangosebrink/remove-app-initializer
FabianGosebrink Nov 21, 2021
eb81ef7
More stuff
FabianGosebrink Nov 21, 2021
2e336b2
More replacements
FabianGosebrink Nov 22, 2021
7867523
more replacements
FabianGosebrink Nov 22, 2021
95a25b1
MOre refactorings
FabianGosebrink Nov 22, 2021
4345a4f
fixed all services except facade
FabianGosebrink Nov 23, 2021
16152cc
More things
FabianGosebrink Nov 23, 2021
feae652
fixed code
FabianGosebrink Nov 23, 2021
64ed82c
Getting closer
FabianGosebrink Nov 23, 2021
6dfdb18
Added better authwellknown handling
FabianGosebrink Nov 23, 2021
7e900a2
Fixed refresh
FabianGosebrink Nov 23, 2021
97a68e1
Fix: Multiple Logins
FabianGosebrink Nov 24, 2021
7a403e0
fixed multiple methods and added preloading method
FabianGosebrink Nov 24, 2021
498a88e
starting to migrate tests
FabianGosebrink Nov 25, 2021
c8d5577
Fix: Dataservice
FabianGosebrink Nov 27, 2021
929aeb1
Fix Tests
FabianGosebrink Nov 27, 2021
261b522
More tests merged
FabianGosebrink Nov 27, 2021
e241ee1
More Tests merged
FabianGosebrink Nov 27, 2021
7fe8d03
More Tests
FabianGosebrink Nov 27, 2021
9bf6ea8
MOre tests
FabianGosebrink Nov 27, 2021
68d3096
MOre tests
FabianGosebrink Nov 27, 2021
03539f6
More tests
FabianGosebrink Nov 27, 2021
475c7ad
More services
FabianGosebrink Nov 28, 2021
6513ffb
More Tests
FabianGosebrink Nov 28, 2021
6e668d1
More Tests
FabianGosebrink Nov 28, 2021
b2cc286
MOre tests
FabianGosebrink Nov 29, 2021
ba58a07
Merge branch 'main' into fabiangosebrink/remove-app-initializer
FabianGosebrink Dec 1, 2021
49d399d
merged more services
FabianGosebrink Dec 1, 2021
54e286e
Fix build
FabianGosebrink Dec 2, 2021
0289a99
Fix more tests
FabianGosebrink Dec 2, 2021
ba65363
Fixing more tests
FabianGosebrink Dec 3, 2021
9b8fcb2
Fix more tests and cleanup
FabianGosebrink Dec 3, 2021
e069558
Fixed some tests
FabianGosebrink Dec 6, 2021
5bb9548
Merge branch 'main' into fabiangosebrink/remove-app-initializer
FabianGosebrink Dec 6, 2021
152cbb1
fixed tests
FabianGosebrink Dec 11, 2021
2fabc04
Fixed some more tests
FabianGosebrink Dec 11, 2021
9a9ae71
some more tests
FabianGosebrink Dec 11, 2021
95e6f34
fixed more tests
FabianGosebrink Dec 11, 2021
23b0802
more tests
FabianGosebrink Dec 11, 2021
fd2dabe
more tests
FabianGosebrink Dec 11, 2021
9c14867
more tests
FabianGosebrink Dec 11, 2021
ab368bd
fix more tests
FabianGosebrink Dec 11, 2021
d8b8e8e
more tests
FabianGosebrink Dec 11, 2021
ba9151c
added more tests
FabianGosebrink Dec 11, 2021
83242a1
Added more tests
FabianGosebrink Dec 11, 2021
a854334
Fixed more tests
FabianGosebrink Dec 11, 2021
70b4af1
more testing
FabianGosebrink Dec 11, 2021
d4fa184
Fixed more tests
FabianGosebrink Dec 12, 2021
9a56cdf
a little more testi testi
FabianGosebrink Dec 12, 2021
3eea6c0
moved service to better place
FabianGosebrink Dec 12, 2021
68e00b8
more tests
FabianGosebrink Dec 12, 2021
a001231
MOre tests
FabianGosebrink Dec 12, 2021
f673516
More tests
FabianGosebrink Dec 12, 2021
131d87c
MOre tests
FabianGosebrink Dec 12, 2021
7ad6871
more tests
FabianGosebrink Dec 12, 2021
9c5050a
Fixed samples
FabianGosebrink Dec 12, 2021
d34d9d8
added more test and tooling
FabianGosebrink Dec 12, 2021
c49a74e
Fix build
FabianGosebrink Dec 12, 2021
cd4e9eb
Fix some tests
FabianGosebrink Dec 13, 2021
898bad6
Fixed all tests
FabianGosebrink Dec 13, 2021
4e89aed
First shot of docs
FabianGosebrink Dec 13, 2021
21168bb
Updated docs
FabianGosebrink Dec 13, 2021
e65ab95
More docs
FabianGosebrink Dec 13, 2021
562ef70
Added new issue template
FabianGosebrink Dec 13, 2021
af41588
Fix spelling mistakes
FabianGosebrink Dec 13, 2021
54c7b19
Fix documentation
FabianGosebrink Dec 13, 2021
787090e
removed old config
FabianGosebrink Dec 13, 2021
56da20b
Updated Docs
FabianGosebrink Dec 20, 2021
78c58ef
Fixed the comment
FabianGosebrink Dec 20, 2021
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
7 changes: 7 additions & 0 deletions .github/ISSUE_TEMPLATE/refactoring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: Code refactoring
about: Any code improvements which make the code better
title: ''
labels: ''
assignees: 'FabianGosebrink'
---
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@
- refactored configuration for module, angular style
- rename OpenIDImplicitFlowConfiguration to OpenIDConfiguration

## Breaking changes
### Breaking changes

Before

Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,21 @@ export class AppComponent implements OnInit {
You can get the access token by calling the method `getAccessToken()` on the `OidcSecurityService`

```ts
const token = this.oidcSecurityService.getAccessToken();
const token = this.oidcSecurityService.getAccessToken().subscribe(...);
```

And then you can use it in the HttpHeaders

```ts
import { HttpHeaders } from '@angular/common/http';

const token = this.oidcSecurityServices.getAccessToken();

const httpOptions = {
headers: new HttpHeaders({
Authorization: 'Bearer ' + token,
}),
};
const token = this.oidcSecurityServices.getAccessToken().subscribe((token) => {
const httpOptions = {
headers: new HttpHeaders({
Authorization: 'Bearer ' + token,
}),
};
});
```

## Versions
Expand Down
2 changes: 1 addition & 1 deletion angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -1802,7 +1802,7 @@
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/",
"outputPath": "dist/sample-code-flow-par",
"index": "projects/sample-code-flow-par/src/index.html",
"main": "projects/sample-code-flow-par/src/main.ts",
"polyfills": "projects/sample-code-flow-par/src/polyfills.ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ If you are using the silent renew process and set this parameter, the supplied U
- Type: `number`
- Required: `false`

Sets the maximum wait time for the silent renew process. If this time is exceeded, the silent renew state will be reset. Default = *20*
Sets the maximum wait time for the silent renew process. If this time is exceeded, the silent renew state will be reset. Default = _20_

### `renewTimeBeforeTokenExpiresInSeconds`

Expand All @@ -291,7 +291,7 @@ Makes it possible to add an offset to the silent renew check in seconds. By ente
- Required: `false`

If set to true, refresh tokens will be used for the silent renew process instead of the default iframes. <br/>
Default = *false*
Default = _false_

### `ignoreNonceAfterRefresh`

Expand Down Expand Up @@ -424,22 +424,15 @@ Disables the `auth_time` validation for `id_tokens` in a refresh due to Microsof
- Required: `false`

Enables the `id_token` validation. You can disable this validation if you would like to ignore expired values during the renew process. If no `id_token` is returned while using refresh tokens, set this to false. <br/>
Default = *true*

### `eagerLoadAuthWellKnownEndpoints`

- Type: `boolean`
- Required: `false`

Denotes whether `AuthWellKnownEndpoints` should be loaded on start or when the user calls the `authorize` method.
Default = _true_

### `tokenRefreshInSeconds`

- Type: `number`
- Required: `false`

Controls the periodic check time interval in seconds. <br/>
Default = *3*
Default = _3_

### `secureRoutes`

Expand All @@ -454,7 +447,7 @@ See [Http Interceptor](./using-access-tokens.md/#http-interceptor)
- Type: `boolean`
- Required: `false`

Activates Pushed Authorisation Requests (PAR) for login and popup login. <br/>
Activates Pushed Authorisation Requests (PAR) for login and popup login. <br/>
(iframe renew is not supported)

### `refreshTokenRetryInSeconds`
Expand All @@ -463,7 +456,7 @@ Activates Pushed Authorisation Requests (PAR) for login and popup login. <br/>
- Required: `false`

Controls the periodic retry time interval for retrieving new tokens in seconds. <br/>
Default = *3*. <br/>
Default = _3_. <br/>
`silentRenewTimeoutInSeconds` and `tokenRefreshInSeconds` are the upper bounds for this value.

### `ngswBypass`
Expand Down

This file was deleted.

80 changes: 46 additions & 34 deletions docs/site/angular-auth-oidc-client/docs/documentation/public-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,19 @@ The `stsCallback$` observable emits _after_ the library has handled the possible
this.stsCallback$ = this.oidcSecurityService.stsCallback$;
```

## preloadAuthWellKnownDocument(configId?: string)

With this method you can explicitly load your auth well-known document to persist it in the configured storage of the lib. This method will perform an http call to load and then save the information. If you do not call this method explicitly, the lib will call it when it is needed for the first time automatically.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method allows you to explicitly load the secure token servers well-known endpoints and persist the settings to the configured storage of this library. This method will perform an http call to load and save the information. If you do not call this method explicitly, the lib will call it when it is needed for the first time automatically.

```ts
// single config
this.oidcSecurityService.preloadAuthWellKnownDocument().subscribe((authWellKnown)=> ... );

// multiple configs
this.oidcSecurityService.preloadAuthWellKnownDocument('configId').subscribe((authWellKnown)=> ... );

```

## getConfigurations()

This method returns all configurations you have configured as an `OpenIdConfiguration[]`. The config includes all your values merged with the ones the library created.
Expand All @@ -174,28 +187,28 @@ const allConfigs = this.oidcSecurityService.getConfigurations();

## getConfiguration(configId?: string)

This method returns one single configuration.
This method returns an observable of one single configuration.
If you are running with multiple configs and pass a `configId`, the configuration or `null` is returned. If you are running with multiple configs and do not pass the `configId`, the first one is returned. If you are running with a single config, then this config is returned.

```ts
// one config or the first one in case of multiple or null
const singleConfig = this.oidcSecurityService.getConfiguration();
this.oidcSecurityService.getConfiguration().subscribe((config)=> ... );

// one config or null
const singleConfig = this.oidcSecurityService.getConfiguration('configId');
this.oidcSecurityService.getConfiguration('configId').subscribe((config)=> ... );
```

## getUserData(configId?: string)

This method returns the user data.
This method returns an observable of the user data.
If you are running with multiple configs and pass a `configId`, the user data for this config or `null` is returned. If you are running with multiple configs and do not pass the `configId`, the user data for the first config is returned. If you are running with a single config, the user data for this config is returned.

```ts
// one config or the first one in case of multiple or null
const userData = this.oidcSecurityService.getUserData();
this.oidcSecurityService.getUserData().subscribe((data)=> ... );

// user data for this specific config
const userData = this.oidcSecurityService.getUserData('configId');
this.oidcSecurityService.getUserData('configId').subscribe((data)=> ... );
```

## checkAuth(url?: string, configId?: string)
Expand Down Expand Up @@ -234,7 +247,7 @@ this.oidcSecurityService.checkAuth(url, configId).subscribe(({ isAuthenticated,
});
```

## checkAuthMultiple(url?: string, configId?: string)
## checkAuthMultiple(url?: string)

This method starts the complete authentication flow for multiple configs. Use this method if you are running with multiple configs to check which one is authenticated or not.

Expand Down Expand Up @@ -265,24 +278,23 @@ You can also pass a `configId` to check for as well as a URL in case you want to

```ts
const url = '...';
const configId = '...';

this.oidcSecurityService.checkAuthMultiple(url, configId).subscribe(({ isAuthenticated, userData, accessToken, idToken, configId }) => {
this.oidcSecurityService.checkAuthMultiple(url).subscribe(({ isAuthenticated, userData, accessToken, idToken, configId }) => {
// ...use data
});
```

## isAuthenticated(configId?: string)

This method provides information if a config is authenticated or not as a `boolean` return value.
This method provides information if a config is authenticated or not as an `Observable<boolean>` return value.
If you are running with multiple configs and pass the `configId` the authentication for this config is checked. If you are running with multiple configs and do not pass the `configId` the authentication for the first config is checked. If you are running with a single config this configuration is checked if you are authenticated.

```ts
const isAuthenticated = this.oidcSecurityService.isAuthenticated();
this.oidcSecurityService.isAuthenticated().subscribe((isAuthenticated)=> ... );
```

```ts
const isAuthenticated = this.oidcSecurityService.isAuthenticated('configId');
this.oidcSecurityService.isAuthenticated('configId').subscribe((isAuthenticated)=> ... );
```

## checkAuthIncludingServer(configId?: string)
Expand Down Expand Up @@ -314,68 +326,68 @@ this.oidcSecurityService.checkAuthIncludingServer('configId').subscribe(/*...*/)

## getAccessToken(configId?: string):

Returns the access token for your login scenario as a `string`.
Returns the access token for your login scenario as an `Observable<string>`.
If you are running with multiple configs and pass the `configId` the access token for this config is returned. If you are running with multiple configs and do not pass the `configId` the access token for the first config is returned. If you are running with a single config the access token for this config returned.

```ts
const accessToken = this.oidcSecurityService.getAccessToken();
this.oidcSecurityService.getAccessToken().subscribe(/*...*/);
```

```ts
const accessToken = this.oidcSecurityService.getAccessToken('configId');
this.oidcSecurityService.getAccessToken('configId').subscribe(/*...*/);
```

## getIdToken(configId?: string):

Returns the id token for your login scenario as a `string`.
Returns the id token for your login scenario as an `Observable<string>`.
If you are running with multiple configs and pass the `configId` the id token for this config is returned. If you are running with multiple configs and do not pass the `configId` the id token for the first config is returned. If you are running with a single config the id token for this config returned.

```ts
const idToken = this.oidcSecurityService.getIdToken();
this.oidcSecurityService.getIdToken().subscribe(/*...*/);
```

```ts
const idToken = this.oidcSecurityService.getIdToken('configId');
this.oidcSecurityService.getIdToken('configId').subscribe(/*...*/);
```

## getRefreshToken(configId?: string)

Returns the refresh token for your login scenario if there is one.
Returns the refresh token as an `Observable<string>` for your login scenario if there is one.
If you are running with multiple configs and pass a `configId`, the refresh token for this config is returned. If you are running with multiple configs and do not pass the `configId`, the refresh token for the first config is returned. If you are running with a single config, the refresh token for this config is returned.

```ts
const refreshToken = this.oidcSecurityService.getRefreshToken();
this.oidcSecurityService.getRefreshToken().subscribe(/*...*/);
```

```ts
const refreshToken = this.oidcSecurityService.getRefreshToken('configId');
this.oidcSecurityService.getRefreshToken('configId').subscribe(/*...*/);
```

## getAuthenticationResult(configId?: string)

Returns the authentication result, if present, for the sign-in. The `configId` parameter is used to define which configuration to use. This is only required when using multiple configurations. If not passed, the first config will be taken. An object with the authentication result is returned.
Returns the authentication result as an `Observable`, if present, for the sign-in. The `configId` parameter is used to define which configuration to use. This is only required when using multiple configurations. If not passed, the first config will be taken. An object with the authentication result is returned.

```ts
const authnResult = this.oidcSecurityService.getAuthenticationResult();
this.oidcSecurityService.getAuthenticationResult().subscribe(/*...*/);
```

```ts
const authnResult = this.oidcSecurityService.getAuthenticationResult('configId');
this.oidcSecurityService.getAuthenticationResult('configId').subscribe(/*...*/);
```

## getPayloadFromIdToken(encode = false, configId?: string)

Returns the payload from the id_token. This can be used to get claims from the token.
Returns the payload from the id_token as an `Observable`. This can be used to get claims from the token.
If you are running with multiple configs and pass a `configId`, the payload for this config is returned. If you are running with multiple configs and do not pass a `configId`, the payload for the first config is returned. If you are running with a single config, the payload for this config returned.

The `encode` param has to be set to `true` if the payload is base64 encoded.

```ts
const payload = this.oidcSecurityService.getPayloadFromIdToken();
this.oidcSecurityService.getPayloadFromIdToken().subscribe(/*...*/);
```

```ts
const payload = this.oidcSecurityService.getPayloadFromIdToken(true, 'configId');
this.oidcSecurityService.getPayloadFromIdToken(true, 'configId').subscribe(/*...*/);
```

## setState(state: string, configId?: string)
Expand All @@ -384,24 +396,24 @@ You can set the state value used for the authorize request, if you have `autoCle
If you are running with multiple configs and pass a `configId`, the passed config is taken. If you are running with multiple configs and do not pass a `configId`, the first config is taken. If you are running with a single config, then this config is taken.

```ts
this.oidcSecurityService.setState('some-state');
this.oidcSecurityService.setState('some-state').subscribe(/*...*/);
```

```ts
this.oidcSecurityService.setState('some-state', 'configId');
this.oidcSecurityService.setState('some-state', 'configId').subscribe(/*...*/);
```

## getState(configId?: string)

Returns the state value used for the authorize request.
Returns the state value used for the authorize request as an `Observable`.
If you are running with multiple configs and pass a `configId`, the passed config is taken. If you are running with multiple configs and do not pass a `configId`, the first config is taken. If you are running with a single config, then this config is taken.

```ts
const state = this.oidcSecurityService.getState();
this.oidcSecurityService.getState().subscribe(/*...*/);
```

```ts
const state = this.oidcSecurityService.getState('configId');
this.oidcSecurityService.getState('configId').subscribe(/*...*/);
```

## authorize(configId?: string, authOptions?: AuthOptions)
Expand Down Expand Up @@ -635,15 +647,15 @@ More info: [https://tools.ietf.org/html/rfc7009](https://tools.ietf.org/html/rfc
Creates the end session URL which can be used to implement your own custom server logout. You can pass custom params directly into the method. This method also takes a `configId`. If you are running with multiple configs and pass a `configId`, the passed config is taken. If you are running with multiple configs and do not pass a `configId`, the first config is taken. If you are running with a single config, then this config is taken.

```ts
const endSessionUrl = this.oidcSecurityService.getEndSessionUrl();
this.oidcSecurityService.getEndSessionUrl().subscribe(/* ... */);
```

```ts
const customParams = {
some: 'params',
};

const endSessionUrl = this.oidcSecurityService.getEndSessionUrl(customParams, 'configId');
this.oidcSecurityService.getEndSessionUrl(customParams, 'configId').subscribe(/* ... */);
```

## getAuthorizeUrl(customParams?: { ... }, configId?: string)
Expand Down
Loading