Skip to content

Commit

Permalink
docs: sort migrations from new to old
Browse files Browse the repository at this point in the history
  • Loading branch information
timdeschryver committed Jul 1, 2023
1 parent bb5bccc commit 668d8c0
Show file tree
Hide file tree
Showing 5 changed files with 245 additions and 119 deletions.
222 changes: 134 additions & 88 deletions docs/site/angular-auth-oidc-client/docs/migrations/v10-to-v11.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 1
sidebar_position: 100
---

# Version 10 to 11
Expand All @@ -10,7 +10,8 @@ sidebar_position: 1

```ts
export function loadConfig(oidcConfigService: OidcConfigService) {
return () => oidcConfigService.load_using_stsServer('https://localhost:44318');
return () =>
oidcConfigService.load_using_stsServer('https://localhost:44318');
}

@NgModule({
Expand All @@ -36,31 +37,39 @@ export function loadConfig(oidcConfigService: OidcConfigService) {
bootstrap: [AppComponent],
})
export class AppModule {
constructor(private oidcSecurityService: OidcSecurityService, private oidcConfigService: OidcConfigService) {
this.oidcConfigService.onConfigurationLoaded.subscribe((configResult: ConfigResult) => {
const config: OpenIdConfiguration = {
stsServer: 'https://localhost:44318',
redirect_url: 'https://localhost:44395',
client_id: 'angularclient2',
response_type: 'code',
scope: 'dataEventRecords openid profile email',
post_logout_redirect_uri: 'https://localhost:44395/unauthorized',
start_checksession: false,
silent_renew: true,
silent_renew_url: 'https://localhost:44395/silent-renew.html',
post_login_route: '/dm',
forbidden_route: '/unauthorized',
unauthorized_route: '/unauthorized',
log_console_warning_active: true,
log_console_debug_active: false,
max_id_token_iat_offset_allowed_in_seconds: 10,
history_cleanup_off: true,
// iss_validation_off: false
// disable_iat_offset_validation: true
};

this.oidcSecurityService.setupModule(config, configResult.authWellknownEndpoints);
});
constructor(
private oidcSecurityService: OidcSecurityService,
private oidcConfigService: OidcConfigService
) {
this.oidcConfigService.onConfigurationLoaded.subscribe(
(configResult: ConfigResult) => {
const config: OpenIdConfiguration = {
stsServer: 'https://localhost:44318',
redirect_url: 'https://localhost:44395',
client_id: 'angularclient2',
response_type: 'code',
scope: 'dataEventRecords openid profile email',
post_logout_redirect_uri: 'https://localhost:44395/unauthorized',
start_checksession: false,
silent_renew: true,
silent_renew_url: 'https://localhost:44395/silent-renew.html',
post_login_route: '/dm',
forbidden_route: '/unauthorized',
unauthorized_route: '/unauthorized',
log_console_warning_active: true,
log_console_debug_active: false,
max_id_token_iat_offset_allowed_in_seconds: 10,
history_cleanup_off: true,
// iss_validation_off: false
// disable_iat_offset_validation: true
};

this.oidcSecurityService.setupModule(
config,
configResult.authWellknownEndpoints
);
}
);
}
}
```
Expand Down Expand Up @@ -115,10 +124,16 @@ export class AppModule {}
```ts
// imports
import { NgModule, APP_INITIALIZER } from '@angular/core';
import { AuthModule, OidcConfigService, ConfigResult, OpenIdConfiguration } from 'angular-auth-oidc-client';
import {
AuthModule,
OidcConfigService,
ConfigResult,
OpenIdConfiguration,
} from 'angular-auth-oidc-client';

export function loadConfig(oidcConfigService: OidcConfigService) {
return () => oidcConfigService.load(`${window.location.origin}/api/ClientAppSettings`);
return () =>
oidcConfigService.load(`${window.location.origin}/api/ClientAppSettings`);
}
@NgModule({
imports: [
Expand All @@ -144,31 +159,44 @@ export function loadConfig(oidcConfigService: OidcConfigService) {
bootstrap: [AppComponent],
})
export class AppModule {
constructor(private oidcSecurityService: OidcSecurityService, private oidcConfigService: OidcConfigService) {
this.oidcConfigService.onConfigurationLoaded.subscribe((configResult: ConfigResult) => {
const config: OpenIdConfiguration = {
stsServer: configResult.customConfig.stsServer,
redirect_url: configResult.customConfig.redirect_url,
client_id: configResult.customConfig.client_id,
response_type: configResult.customConfig.response_type,
scope: configResult.customConfig.scope,
post_logout_redirect_uri: configResult.customConfig.post_logout_redirect_uri,
start_checksession: configResult.customConfig.start_checksession,
silent_renew: configResult.customConfig.silent_renew,
silent_renew_url: 'https://localhost:44311/silent-renew.html',
post_login_route: configResult.customConfig.startup_route,
forbidden_route: configResult.customConfig.forbidden_route,
unauthorized_route: configResult.customConfig.unauthorized_route,
log_console_warning_active: configResult.customConfig.log_console_warning_active,
log_console_debug_active: configResult.customConfig.log_console_debug_active,
max_id_token_iat_offset_allowed_in_seconds: configResult.customConfig.max_id_token_iat_offset_allowed_in_seconds,
history_cleanup_off: true,
// iss_validation_off: false
// disable_iat_offset_validation: true
};

this.oidcSecurityService.setupModule(config, configResult.authWellknownEndpoints);
});
constructor(
private oidcSecurityService: OidcSecurityService,
private oidcConfigService: OidcConfigService
) {
this.oidcConfigService.onConfigurationLoaded.subscribe(
(configResult: ConfigResult) => {
const config: OpenIdConfiguration = {
stsServer: configResult.customConfig.stsServer,
redirect_url: configResult.customConfig.redirect_url,
client_id: configResult.customConfig.client_id,
response_type: configResult.customConfig.response_type,
scope: configResult.customConfig.scope,
post_logout_redirect_uri:
configResult.customConfig.post_logout_redirect_uri,
start_checksession: configResult.customConfig.start_checksession,
silent_renew: configResult.customConfig.silent_renew,
silent_renew_url: 'https://localhost:44311/silent-renew.html',
post_login_route: configResult.customConfig.startup_route,
forbidden_route: configResult.customConfig.forbidden_route,
unauthorized_route: configResult.customConfig.unauthorized_route,
log_console_warning_active:
configResult.customConfig.log_console_warning_active,
log_console_debug_active:
configResult.customConfig.log_console_debug_active,
max_id_token_iat_offset_allowed_in_seconds:
configResult.customConfig
.max_id_token_iat_offset_allowed_in_seconds,
history_cleanup_off: true,
// iss_validation_off: false
// disable_iat_offset_validation: true
};

this.oidcSecurityService.setupModule(
config,
configResult.authWellknownEndpoints
);
}
);
}
}
```
Expand All @@ -181,29 +209,35 @@ import { HttpClient, HttpClientModule } from '@angular/common/http';
import { AuthModule, OidcConfigService } from 'angular-auth-oidc-client';
import { map, switchMap } from 'rxjs/operators';

export function configureAuth(oidcConfigService: OidcConfigService, httpClient: HttpClient) {
const setupAction$ = httpClient.get<any>(`${window.location.origin}/api/ClientAppSettings`).pipe(
map((customConfig) => {
return {
stsServer: customConfig.stsServer,
redirectUrl: customConfig.redirect_url,
clientId: customConfig.client_id,
responseType: customConfig.response_type,
scope: customConfig.scope,
postLogoutRedirectUri: customConfig.post_logout_redirect_uri,
startCheckSession: customConfig.start_checksession,
silentRenew: true,
silentRenewUrl: customConfig.redirect_url + '/silent-renew.html',
postLoginRoute: customConfig.startup_route,
forbiddenRoute: customConfig.forbidden_route,
unauthorizedRoute: customConfig.unauthorized_route,
logLevel: 0, // LogLevel.Debug, // customConfig.logLevel
maxIdTokenIatOffsetAllowedInSeconds: customConfig.max_id_token_iat_offset_allowed_in_seconds,
historyCleanupOff: true,
};
}),
switchMap((config) => oidcConfigService.withConfig(config))
);
export function configureAuth(
oidcConfigService: OidcConfigService,
httpClient: HttpClient
) {
const setupAction$ = httpClient
.get<any>(`${window.location.origin}/api/ClientAppSettings`)
.pipe(
map((customConfig) => {
return {
stsServer: customConfig.stsServer,
redirectUrl: customConfig.redirect_url,
clientId: customConfig.client_id,
responseType: customConfig.response_type,
scope: customConfig.scope,
postLogoutRedirectUri: customConfig.post_logout_redirect_uri,
startCheckSession: customConfig.start_checksession,
silentRenew: true,
silentRenewUrl: customConfig.redirect_url + '/silent-renew.html',
postLoginRoute: customConfig.startup_route,
forbiddenRoute: customConfig.forbidden_route,
unauthorizedRoute: customConfig.unauthorized_route,
logLevel: 0, // LogLevel.Debug, // customConfig.logLevel
maxIdTokenIatOffsetAllowedInSeconds:
customConfig.max_id_token_iat_offset_allowed_in_seconds,
historyCleanupOff: true,
};
}),
switchMap((config) => oidcConfigService.withConfig(config))
);

return () => setupAction$.toPromise();
}
Expand Down Expand Up @@ -259,9 +293,11 @@ export class AppComponent implements OnInit, OnDestroy {
}

ngOnInit() {
this.isAuthorizedSubscription = this.oidcSecurityService.getIsAuthorized().subscribe((isAuthorized: boolean) => {
this.isAuthorized = isAuthorized;
});
this.isAuthorizedSubscription = this.oidcSecurityService
.getIsAuthorized()
.subscribe((isAuthorized: boolean) => {
this.isAuthorized = isAuthorized;
});
}

ngOnDestroy(): void {
Expand All @@ -272,7 +308,9 @@ export class AppComponent implements OnInit, OnDestroy {

private doCallbackLogicIfRequired() {
// Will do a callback, if the url has a code and state parameter.
this.oidcSecurityService.authorizedCallbackWithCode(window.location.toString());
this.oidcSecurityService.authorizedCallbackWithCode(
window.location.toString()
);
}
}
```
Expand All @@ -297,7 +335,11 @@ export class AppComponent implements OnInit {
ngOnInit() {
this.isAuthenticated$ = this.oidcSecurityService.isAuthenticated$;

this.oidcSecurityService.checkAuth().subscribe((isAuthenticated) => console.log('app authenticated', isAuthenticated));
this.oidcSecurityService
.checkAuth()
.subscribe((isAuthenticated) =>
console.log('app authenticated', isAuthenticated)
);
}
}
```
Expand All @@ -307,17 +349,21 @@ export class AppComponent implements OnInit {
### Old

```ts
this.oidcSecurityService.getIsAuthorized().subscribe((isAuthenticated: boolean) => {
// work with `isAuthenticated`
});
this.oidcSecurityService
.getIsAuthorized()
.subscribe((isAuthenticated: boolean) => {
// work with `isAuthenticated`
});
```

### New

```ts
this.oidcSecurityService.isAuthenticated$.subscribe((isAuthenticated: boolean) => {
// work with `isAuthenticated`
});
this.oidcSecurityService.isAuthenticated$.subscribe(
(isAuthenticated: boolean) => {
// work with `isAuthenticated`
}
);
```

## User data
Expand Down
Loading

0 comments on commit 668d8c0

Please sign in to comment.