@igo2/auth 20.1.0-next.9 → 21.0.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,80 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Provider, EnvironmentProviders } from '@angular/core';
2
+ import { OnDestroy, Provider, InjectionToken, EnvironmentProviders } from '@angular/core';
3
3
  import { BaseUser } from '@igo2/core/user';
4
- import { JwtPayload } from 'jwt-decode';
5
- import * as rxjs from 'rxjs';
6
- import { BehaviorSubject, Observable } from 'rxjs';
4
+ import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
7
5
  import { StorageOptions, BaseStorage, StorageScope } from '@igo2/core/storage';
6
+ import * as rxjs from 'rxjs';
7
+ import { Observable, BehaviorSubject } from 'rxjs';
8
8
  import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent } from '@angular/common/http';
9
- import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
9
+ import { JwtPayload } from 'jwt-decode';
10
+
11
+ declare class AdminGuard {
12
+ private authService;
13
+ private config;
14
+ private router;
15
+ canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean;
16
+ static ɵfac: i0.ɵɵFactoryDeclaration<AdminGuard, never>;
17
+ static ɵprov: i0.ɵɵInjectableDeclaration<AdminGuard>;
18
+ }
19
+
20
+ type AuthStorageOptions = StorageOptions;
21
+
22
+ declare class AuthStorageService extends BaseStorage<AuthStorageOptions> implements OnDestroy {
23
+ private authService;
24
+ private userService;
25
+ private tokenService;
26
+ private preferencesChanged$;
27
+ private destroy$;
28
+ private pendingPreferences;
29
+ private serverPreferences;
30
+ constructor();
31
+ ngOnDestroy(): void;
32
+ set(key: string, value: string | object | boolean | number, scope?: StorageScope): void;
33
+ remove(key: string, scope?: StorageScope): void;
34
+ clear(scope?: StorageScope): void;
35
+ private syncPreferences;
36
+ static ɵfac: i0.ɵɵFactoryDeclaration<AuthStorageService, never>;
37
+ static ɵprov: i0.ɵɵInjectableDeclaration<AuthStorageService>;
38
+ }
39
+
40
+ declare class AuthGuard {
41
+ private authService;
42
+ private config;
43
+ private router;
44
+ canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean;
45
+ static ɵfac: i0.ɵɵFactoryDeclaration<AuthGuard, never>;
46
+ static ɵprov: i0.ɵɵInjectableDeclaration<AuthGuard>;
47
+ }
10
48
 
49
+ declare class AuthInterceptor implements HttpInterceptor {
50
+ private config;
51
+ private tokenService;
52
+ private http;
53
+ private authOptions;
54
+ private refreshInProgress;
55
+ private trustHosts;
56
+ private hostsWithCredentials;
57
+ private hostsWithAuthByKey;
58
+ constructor();
59
+ intercept(originalReq: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>>;
60
+ interceptXhr(xhr: any, url: string): boolean;
61
+ alterUrlWithKeyAuth(url: string): string;
62
+ private handleHostsWithCredentials;
63
+ private handleHostsAuthByKey;
64
+ refreshToken(): rxjs.Subscription;
65
+ static ɵfac: i0.ɵɵFactoryDeclaration<AuthInterceptor, never>;
66
+ static ɵprov: i0.ɵɵInjectableDeclaration<AuthInterceptor>;
67
+ }
68
+
69
+ interface AuthFacebookOptions {
70
+ enabled?: boolean;
71
+ appId: string;
72
+ }
73
+ interface AuthGoogleOptions {
74
+ enabled?: boolean;
75
+ apiKey: string;
76
+ clientId: string;
77
+ }
11
78
  interface User extends BaseUser {
12
79
  source?: string;
13
80
  sourceId?: string;
@@ -20,10 +87,13 @@ interface IInfosUser {
20
87
  tokenId: string;
21
88
  }
22
89
  interface AuthOptions {
23
- url?: string;
90
+ url: string;
91
+ /** User api url is the igo user versus the url is the authentification API */
92
+ user?: IAuthUserIgoOptions;
24
93
  tokenKey?: string;
25
94
  allowAnonymous?: boolean;
26
95
  loginRoute?: string;
96
+ logoutRedirectRoute?: string;
27
97
  logoutRoute?: string;
28
98
  homeRoute?: string;
29
99
  trustHosts?: string[];
@@ -32,6 +102,15 @@ interface AuthOptions {
32
102
  hostsByKey?: AuthByKeyOptions[];
33
103
  intern?: AuthInternOptions;
34
104
  }
105
+ interface IAuthUserIgoOptions {
106
+ apiUrl: string;
107
+ withSync?: boolean;
108
+ }
109
+ interface AuthByKeyOptions {
110
+ domainRegFilters?: string;
111
+ keyProperty?: string;
112
+ keyValue?: string;
113
+ }
35
114
  interface AuthByKeyOptions {
36
115
  domainRegFilters?: string;
37
116
  keyProperty?: string;
@@ -41,6 +120,13 @@ interface WithCredentialsOptions {
41
120
  withCredentials?: boolean;
42
121
  domainRegFilters?: string;
43
122
  }
123
+ interface WithCredentialsOptions {
124
+ withCredentials?: boolean;
125
+ domainRegFilters?: string;
126
+ }
127
+ interface AuthInternOptions {
128
+ enabled?: boolean;
129
+ }
44
130
  interface AuthInternOptions {
45
131
  enabled?: boolean;
46
132
  }
@@ -49,30 +135,32 @@ interface AuthFeature<KindT extends AuthFeatureKind> {
49
135
  providers: Provider[];
50
136
  }
51
137
  declare enum AuthFeatureKind {
52
- Microsoft = 0
138
+ Microsoft = 0,
139
+ User = 1
53
140
  }
54
141
 
55
142
  interface IgoJwtPayload extends JwtPayload {
56
143
  user: User;
57
144
  }
58
145
 
59
- declare class TokenService {
60
- private injector;
61
- private options?;
62
- private tokenKey;
63
- constructor();
64
- set(token: string): void;
65
- remove(): void;
66
- get(): string;
67
- decode(): IgoJwtPayload | null;
68
- isExpired(): boolean;
69
- static ɵfac: i0.ɵɵFactoryDeclaration<TokenService, never>;
70
- static ɵprov: i0.ɵɵInjectableDeclaration<TokenService>;
146
+ interface IUser {
147
+ id: number;
148
+ defaultContextId: number | null;
149
+ preference: IUserPreference | null;
150
+ externalId: number;
151
+ guides?: string[];
152
+ createdAt: Date;
153
+ updatedAt: Date;
71
154
  }
155
+ type IUserPreference = Record<string, unknown>;
72
156
 
73
- declare class AuthService {
157
+ interface IToken {
158
+ token: string;
159
+ }
160
+ declare class AuthService<T extends AuthOptions = AuthOptions> {
74
161
  private http;
75
162
  private tokenService;
163
+ private userService;
76
164
  private config;
77
165
  private languageService;
78
166
  private messageService;
@@ -81,16 +169,18 @@ declare class AuthService {
81
169
  logged$: BehaviorSubject<boolean>;
82
170
  redirectUrl: string;
83
171
  languageForce: boolean;
172
+ authOptions: T;
84
173
  private anonymous;
85
- private authOptions;
174
+ isLogging: i0.WritableSignal<boolean>;
86
175
  get hasAuthService(): boolean;
87
176
  get user(): User | null;
88
177
  constructor();
89
- login(username: string, password: string): Observable<void>;
90
- loginWithToken(token: string, type: string, infosUser?: IInfosUser): Observable<void>;
178
+ login(username: string, password: string): Observable<IUser>;
179
+ loginWithToken(token: string, type: string, infosUser?: IInfosUser, applicationId?: string): Observable<IUser>;
91
180
  loginAnonymous(): Observable<boolean>;
92
- refresh(): Observable<void>;
93
- logout(): Observable<boolean>;
181
+ refresh(): Observable<IToken>;
182
+ logout(): void;
183
+ private logoutInternal;
94
184
  isAuthenticated(): boolean;
95
185
  getToken(): string;
96
186
  decodeToken(): IgoJwtPayload | null;
@@ -100,50 +190,16 @@ declare class AuthService {
100
190
  profils: string[];
101
191
  }>;
102
192
  updateUser(user: User): Observable<User>;
193
+ translateError(prefix: string, error: any): Observable<string>;
103
194
  private encodePassword;
104
195
  get logged(): boolean;
105
196
  get isAnonymous(): boolean;
106
197
  get authenticated(): boolean;
107
198
  get isAdmin(): boolean;
108
- private loginCall;
109
- static ɵfac: i0.ɵɵFactoryDeclaration<AuthService, never>;
110
- static ɵprov: i0.ɵɵInjectableDeclaration<AuthService>;
111
- }
112
-
113
- interface AuthStorageOptions extends StorageOptions {
114
- url: string;
115
- }
116
-
117
- declare class AuthStorageService extends BaseStorage<AuthStorageOptions> {
118
- private http;
119
- private authService;
120
- private tokenService;
121
- constructor();
122
- set(key: string, value: string | object | boolean | number, scope?: StorageScope): void;
123
- remove(key: string, scope?: StorageScope): void;
124
- clear(scope?: StorageScope): void;
125
- static ɵfac: i0.ɵɵFactoryDeclaration<AuthStorageService, never>;
126
- static ɵprov: i0.ɵɵInjectableDeclaration<AuthStorageService>;
127
- }
128
-
129
- declare class AuthInterceptor implements HttpInterceptor {
130
- private config;
131
- private tokenService;
132
- private http;
133
- private authOptions;
134
- private refreshInProgress;
135
- private trustHosts;
136
- private hostsWithCredentials;
137
- private hostsWithAuthByKey;
138
- constructor();
139
- intercept(originalReq: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>>;
140
- interceptXhr(xhr: any, url: string): boolean;
141
- alterUrlWithKeyAuth(url: string): string;
142
- private handleHostsWithCredentials;
143
- private handleHostsAuthByKey;
144
- refreshToken(): rxjs.Subscription;
145
- static ɵfac: i0.ɵɵFactoryDeclaration<AuthInterceptor, never>;
146
- static ɵprov: i0.ɵɵInjectableDeclaration<AuthInterceptor>;
199
+ protected loginCall(body: any, headers: any): Observable<IUser>;
200
+ private initializeAuthentication;
201
+ static ɵfac: i0.ɵɵFactoryDeclaration<AuthService<any>, never>;
202
+ static ɵprov: i0.ɵɵInjectableDeclaration<AuthService<any>>;
147
203
  }
148
204
 
149
205
  declare class LoggedGuard {
@@ -155,24 +211,6 @@ declare class LoggedGuard {
155
211
  static ɵprov: i0.ɵɵInjectableDeclaration<LoggedGuard>;
156
212
  }
157
213
 
158
- declare class AuthGuard {
159
- private authService;
160
- private config;
161
- private router;
162
- canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean;
163
- static ɵfac: i0.ɵɵFactoryDeclaration<AuthGuard, never>;
164
- static ɵprov: i0.ɵɵInjectableDeclaration<AuthGuard>;
165
- }
166
-
167
- declare class AdminGuard {
168
- private authService;
169
- private config;
170
- private router;
171
- canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean;
172
- static ɵfac: i0.ɵɵFactoryDeclaration<AdminGuard, never>;
173
- static ɵprov: i0.ɵɵInjectableDeclaration<AdminGuard>;
174
- }
175
-
176
214
  declare class ProfilsGuard {
177
215
  private authService;
178
216
  private config;
@@ -182,7 +220,40 @@ declare class ProfilsGuard {
182
220
  static ɵprov: i0.ɵɵInjectableDeclaration<ProfilsGuard>;
183
221
  }
184
222
 
223
+ declare class TokenService {
224
+ private injector;
225
+ private options?;
226
+ private tokenKey;
227
+ constructor();
228
+ set(token: string): void;
229
+ remove(): void;
230
+ get(): string;
231
+ decode(): IgoJwtPayload | null;
232
+ isExpired(): boolean;
233
+ static ɵfac: i0.ɵɵFactoryDeclaration<TokenService, never>;
234
+ static ɵprov: i0.ɵɵInjectableDeclaration<TokenService>;
235
+ }
236
+
237
+ declare const USER_AUTH_OPTIONS: InjectionToken<IAuthUserIgoOptions>;
238
+ declare class UserService {
239
+ private http;
240
+ private options;
241
+ private baseUrl;
242
+ private _user$;
243
+ user$: Observable<IUser>;
244
+ constructor();
245
+ getUser(): Observable<IUser>;
246
+ sync(): Observable<IUser>;
247
+ updatePreference(preference: IUserPreference): Observable<{
248
+ id: number;
249
+ }>;
250
+ static ɵfac: i0.ɵɵFactoryDeclaration<UserService, never>;
251
+ static ɵprov: i0.ɵɵInjectableDeclaration<UserService>;
252
+ }
253
+
254
+ declare function withUserIgo(): AuthFeature<AuthFeatureKind.User>;
255
+
185
256
  declare function provideAuthentification(...features: AuthFeature<AuthFeatureKind>[]): EnvironmentProviders;
186
257
 
187
- export { AdminGuard, AuthFeatureKind, AuthGuard, AuthInterceptor, AuthService, AuthStorageService, LoggedGuard, ProfilsGuard, TokenService, provideAuthentification };
188
- export type { AuthByKeyOptions, AuthFeature, AuthInternOptions, AuthOptions, AuthStorageOptions, IInfosUser, IgoJwtPayload, User, WithCredentialsOptions };
258
+ export { AdminGuard, AuthFeatureKind, AuthGuard, AuthInterceptor, AuthService, AuthStorageService, LoggedGuard, ProfilsGuard, TokenService, USER_AUTH_OPTIONS, UserService, provideAuthentification, withUserIgo };
259
+ export type { AuthByKeyOptions, AuthFacebookOptions, AuthFeature, AuthGoogleOptions, AuthInternOptions, AuthOptions, AuthStorageOptions, IAuthUserIgoOptions, IInfosUser, IUser, IUserPreference, IgoJwtPayload, User, WithCredentialsOptions };