Skip to content

Commit 521f399

Browse files
Merge pull request #1917 from damienbod/feature/fg/moving-to-inject-function
Moving to inject function
2 parents 3465e3d + 04f002a commit 521f399

File tree

105 files changed

+737
-551
lines changed

Some content is hidden

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

105 files changed

+737
-551
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@ export class AppModule {}
112112
And call the method `checkAuth()` from your `app.component.ts`. The method `checkAuth()` is needed to process the redirect from your Security Token Service and set the correct states. This method must be used to ensure the correct functioning of the library.
113113

114114
```ts
115-
import { Component, OnInit } from '@angular/core';
115+
import { Component, OnInit, inject } from '@angular/core';
116116
import { OidcSecurityService } from 'angular-auth-oidc-client';
117117

118118
@Component({
119119
/*...*/
120120
})
121121
export class AppComponent implements OnInit {
122-
constructor(public oidcSecurityService: OidcSecurityService) {}
122+
private readonly oidcSecurityService = inject(OidcSecurityService);
123123

124124
ngOnInit() {
125125
this.oidcSecurityService

docs/site/angular-auth-oidc-client/docs/documentation/auto-login.md

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,15 @@ import { AutoLoginPartialRoutesGuard } from 'angular-auth-oidc-client';
2727
const routes: Routes = [
2828
{ path: '', pathMatch: 'full', redirectTo: 'home' },
2929
{ path: 'home', component: HomeComponent },
30-
{ path: 'protected', component: ProtectedComponent, canActivate: [AutoLoginPartialRoutesGuard] },
30+
{
31+
path: 'protected',
32+
component: ProtectedComponent,
33+
canActivate: [AutoLoginPartialRoutesGuard],
34+
},
3135
{
3236
path: 'customers',
33-
loadChildren: () => import('./customers/customers.module').then((m) => m.CustomersModule),
37+
loadChildren: () =>
38+
import('./customers/customers.module').then((m) => m.CustomersModule),
3439
canLoad: [AutoLoginPartialRoutesGuard],
3540
},
3641
{ path: 'unauthorized', component: UnauthorizedComponent },
@@ -42,12 +47,14 @@ Please make sure to call `checkAuth()` like normal in your `app.component.ts`.
4247

4348
```ts
4449
export class AppComponent implements OnInit {
45-
constructor(private oidcSecurityService: OidcSecurityService) {}
50+
private readonly oidcSecurityService = inject(OidcSecurityService);
4651

4752
ngOnInit() {
48-
this.oidcSecurityService.checkAuth().subscribe(({ isAuthenticated, userData, accessToken }) => {
49-
// ...
50-
});
53+
this.oidcSecurityService
54+
.checkAuth()
55+
.subscribe(({ isAuthenticated, userData, accessToken }) => {
56+
// ...
57+
});
5158
}
5259
}
5360
```
@@ -69,20 +76,31 @@ import { AutoLoginPartialRoutesGuard } from 'angular-auth-oidc-client';
6976

7077
const routes: Routes = [
7178
{ path: '', pathMatch: 'full', redirectTo: 'home' },
72-
{ path: 'home', component: HomeComponent, canActivate: [AutoLoginPartialRoutesGuard] },
79+
{
80+
path: 'home',
81+
component: HomeComponent,
82+
canActivate: [AutoLoginPartialRoutesGuard],
83+
},
7384
{ path: 'callback', component: CallbackComponent }, // does nothing but setting up auth
7485
];
7586
```
87+
7688
### Custom Params for the guard
7789

78-
If you need to pass custom params to the login request you can simply use the [data](https://angular.io/api/router/Route#data) attribute of the route.
90+
If you need to pass custom params to the login request you can simply use the [data](https://angular.io/api/router/Route#data) attribute of the route.
7991
These parameters will then be appended to the login request
92+
8093
```ts
8194
import { AutoLoginPartialRoutesGuard } from 'angular-auth-oidc-client';
8295

8396
const routes: Routes = [
8497
{ path: '', pathMatch: 'full', redirectTo: 'home' },
85-
{ path: 'home', component: HomeComponent, canActivate: [AutoLoginPartialRoutesGuard], data:{custom:'param'} },
98+
{
99+
path: 'home',
100+
component: HomeComponent,
101+
canActivate: [AutoLoginPartialRoutesGuard],
102+
data: { custom: 'param' },
103+
},
86104
{ path: 'callback', component: CallbackComponent }, // does nothing but setting up auth
87105
];
88106
```

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,26 @@ Please refer to the auto-login guard in this repo as a reference. It is importan
1313

1414
```ts
1515
import { Injectable } from '@angular/core';
16-
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree } from '@angular/router';
16+
import {
17+
ActivatedRouteSnapshot,
18+
CanActivate,
19+
Router,
20+
RouterStateSnapshot,
21+
UrlTree,
22+
} from '@angular/router';
1723
import { OidcSecurityService } from 'angular-auth-oidc-client';
1824
import { Observable } from 'rxjs';
1925
import { map } from 'rxjs/operators';
2026

2127
@Injectable({ providedIn: 'root' })
2228
export class AuthorizationGuard implements CanActivate {
23-
constructor(private oidcSecurityService: OidcSecurityService, private router: Router) {}
29+
private readonly oidcSecurityService = inject(OidcSecurityService);
30+
private readonly router = inject(Router);
2431

25-
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> {
32+
canActivate(
33+
route: ActivatedRouteSnapshot,
34+
state: RouterStateSnapshot
35+
): Observable<boolean | UrlTree> {
2636
return this.oidcSecurityService.isAuthenticated$.pipe(
2737
take(1),
2838
map(({ isAuthenticated }) => {

docs/site/angular-auth-oidc-client/docs/documentation/login-logout.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ sidebar_position: 3
1010
For logging in a user you can call the `authorize()` method:
1111

1212
```ts
13-
constructor(private oidcSecurityService: OidcSecurityService) {}
13+
private readonly oidcSecurityService = inject(OidcSecurityService);
1414

1515
// ...
1616
this.oidcSecurityService.authorize();
@@ -126,7 +126,8 @@ A simplified page (instead of the application url) can be used. Here's an exampl
126126
</script>
127127
</head>
128128
<body onload="sendMessage()">
129-
Transmitting authentication result ... (this popup will be closed automatically).
129+
Transmitting authentication result ... (this popup will be closed
130+
automatically).
130131
</body>
131132
</html>
132133
```

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ Using the `filter` operator from RxJS you can decide which events you are intere
3737
```ts
3838
import { PublicEventsService } from 'angular-auth-oidc-client';
3939

40-
constructor(private eventService: PublicEventsService) {
40+
private readonly eventService = inject(PublicEventsService);
41+
42+
ngOnInit() {
4143
this.eventService
4244
.registerForEvents()
4345
.pipe(filter((notification) => notification.type === EventTypes.CheckSessionReceived))

docs/site/angular-auth-oidc-client/docs/intro.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ import { OidcSecurityService } from 'angular-auth-oidc-client';
7272
/* ... */
7373
})
7474
export class AppComponent implements OnInit {
75-
constructor(public oidcSecurityService: OidcSecurityService) {}
75+
private readonly oidcSecurityService = inject(OidcSecurityService);
7676

7777
ngOnInit() {
7878
this.oidcSecurityService.checkAuth().subscribe(({ isAuthenticated, userData}) => /* ... */);

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Injectable } from '@angular/core';
1+
import { Injectable, inject } from '@angular/core';
22
import { BehaviorSubject, Observable, throwError } from 'rxjs';
33
import { distinctUntilChanged } from 'rxjs/operators';
44
import { OpenIdConfiguration } from '../config/openid-configuration';
@@ -18,6 +18,16 @@ const DEFAULT_AUTHRESULT = {
1818

1919
@Injectable({ providedIn: 'root' })
2020
export class AuthStateService {
21+
private readonly storagePersistenceService = inject(
22+
StoragePersistenceService
23+
);
24+
25+
private readonly loggerService = inject(LoggerService);
26+
27+
private readonly publicEventsService = inject(PublicEventsService);
28+
29+
private readonly tokenValidationService = inject(TokenValidationService);
30+
2131
private readonly authenticatedInternal$ =
2232
new BehaviorSubject<AuthenticatedResult>(DEFAULT_AUTHRESULT);
2333

@@ -27,13 +37,6 @@ export class AuthStateService {
2737
.pipe(distinctUntilChanged());
2838
}
2939

30-
constructor(
31-
private readonly storagePersistenceService: StoragePersistenceService,
32-
private readonly loggerService: LoggerService,
33-
private readonly publicEventsService: PublicEventsService,
34-
private readonly tokenValidationService: TokenValidationService
35-
) {}
36-
3740
setAuthenticatedAndFireEvent(allConfigs: OpenIdConfiguration[]): void {
3841
const result = this.composeAuthenticatedResult(allConfigs);
3942

projects/angular-auth-oidc-client/src/lib/auth-state/check-auth.service.ts

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Injectable } from '@angular/core';
1+
import { inject, Injectable } from '@angular/core';
22
import { forkJoin, Observable, of, throwError } from 'rxjs';
33
import { catchError, map, switchMap, tap } from 'rxjs/operators';
44
import { AutoLoginService } from '../auto-login/auto-login.service';
@@ -20,21 +20,35 @@ import { AuthStateService } from './auth-state.service';
2020

2121
@Injectable({ providedIn: 'root' })
2222
export class CheckAuthService {
23-
constructor(
24-
private readonly checkSessionService: CheckSessionService,
25-
private readonly currentUrlService: CurrentUrlService,
26-
private readonly silentRenewService: SilentRenewService,
27-
private readonly userService: UserService,
28-
private readonly loggerService: LoggerService,
29-
private readonly authStateService: AuthStateService,
30-
private readonly callbackService: CallbackService,
31-
private readonly refreshSessionService: RefreshSessionService,
32-
private readonly periodicallyTokenCheckService: PeriodicallyTokenCheckService,
33-
private readonly popupService: PopUpService,
34-
private readonly autoLoginService: AutoLoginService,
35-
private readonly storagePersistenceService: StoragePersistenceService,
36-
private readonly publicEventsService: PublicEventsService
37-
) {}
23+
private readonly checkSessionService = inject(CheckSessionService);
24+
25+
private readonly currentUrlService = inject(CurrentUrlService);
26+
27+
private readonly silentRenewService = inject(SilentRenewService);
28+
29+
private readonly userService = inject(UserService);
30+
31+
private readonly loggerService = inject(LoggerService);
32+
33+
private readonly authStateService = inject(AuthStateService);
34+
35+
private readonly callbackService = inject(CallbackService);
36+
37+
private readonly refreshSessionService = inject(RefreshSessionService);
38+
39+
private readonly periodicallyTokenCheckService = inject(
40+
PeriodicallyTokenCheckService
41+
);
42+
43+
private readonly popupService = inject(PopUpService);
44+
45+
private readonly autoLoginService = inject(AutoLoginService);
46+
47+
private readonly storagePersistenceService = inject(
48+
StoragePersistenceService
49+
);
50+
51+
private readonly publicEventsService = inject(PublicEventsService);
3852

3953
private getConfig(
4054
configuration: OpenIdConfiguration,

projects/angular-auth-oidc-client/src/lib/auto-login/auto-login-all-routes.guard.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Injectable } from '@angular/core';
1+
import { Injectable, inject } from '@angular/core';
22
import {
33
ActivatedRouteSnapshot,
44
Router,
@@ -17,13 +17,15 @@ import { AutoLoginService } from './auto-login.service';
1717
*/
1818
@Injectable({ providedIn: 'root' })
1919
export class AutoLoginAllRoutesGuard {
20-
constructor(
21-
private readonly autoLoginService: AutoLoginService,
22-
private readonly checkAuthService: CheckAuthService,
23-
private readonly loginService: LoginService,
24-
private readonly configurationService: ConfigurationService,
25-
private readonly router: Router
26-
) {}
20+
private readonly autoLoginService = inject(AutoLoginService);
21+
22+
private readonly checkAuthService = inject(CheckAuthService);
23+
24+
private readonly loginService = inject(LoginService);
25+
26+
private readonly configurationService = inject(ConfigurationService);
27+
28+
private readonly router = inject(Router);
2729

2830
canLoad(): Observable<boolean> {
2931
const url =

projects/angular-auth-oidc-client/src/lib/auto-login/auto-login-partial-routes.guard.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ import { AutoLoginService } from './auto-login.service';
1414

1515
@Injectable({ providedIn: 'root' })
1616
export class AutoLoginPartialRoutesGuard {
17-
constructor(
18-
private readonly autoLoginService: AutoLoginService,
19-
private readonly authStateService: AuthStateService,
20-
private readonly loginService: LoginService,
21-
private readonly configurationService: ConfigurationService,
22-
private readonly router: Router
23-
) {}
17+
private readonly autoLoginService = inject(AutoLoginService);
18+
19+
private readonly authStateService = inject(AuthStateService);
20+
21+
private readonly loginService = inject(LoginService);
22+
23+
private readonly configurationService = inject(ConfigurationService);
24+
25+
private readonly router = inject(Router);
2426

2527
canLoad(): Observable<boolean> {
2628
const url =

0 commit comments

Comments
 (0)