@acontplus/ng-auth 1.1.2 → 1.1.3
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.
- package/fesm2022/acontplus-ng-auth.mjs +327 -287
- package/fesm2022/acontplus-ng-auth.mjs.map +1 -1
- package/index.d.ts +126 -105
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -1,15 +1,123 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseUseCase, ITokenProvider } from '@acontplus/ng-infrastructure';
|
|
2
2
|
export { ITokenProvider, TOKEN_PROVIDER } from '@acontplus/ng-infrastructure';
|
|
3
|
-
import { CanActivateFn } from '@angular/router';
|
|
4
|
-
import * as i0 from '@angular/core';
|
|
5
|
-
import { OnDestroy, OnInit, TemplateRef, Provider } from '@angular/core';
|
|
6
|
-
import { AuthTokens, UserData } from '@acontplus/core';
|
|
7
|
-
import { HttpInterceptorFn } from '@angular/common/http';
|
|
8
3
|
import { Observable } from 'rxjs';
|
|
4
|
+
import { AuthTokens, UserData } from '@acontplus/core';
|
|
5
|
+
import * as i0 from '@angular/core';
|
|
6
|
+
import { Provider, OnDestroy, OnInit, TemplateRef } from '@angular/core';
|
|
7
|
+
import { CanActivateFn } from '@angular/router';
|
|
8
|
+
import { HttpInterceptorFn, HttpContextToken } from '@angular/common/http';
|
|
9
9
|
import { AbstractControl, FormGroup } from '@angular/forms';
|
|
10
10
|
|
|
11
|
+
interface LoginRequest {
|
|
12
|
+
email: string;
|
|
13
|
+
password: string;
|
|
14
|
+
rememberMe?: boolean;
|
|
15
|
+
}
|
|
16
|
+
interface RegisterRequest {
|
|
17
|
+
email: string;
|
|
18
|
+
displayName: string;
|
|
19
|
+
password: string;
|
|
20
|
+
}
|
|
21
|
+
interface RefreshTokenRequest {
|
|
22
|
+
email: string;
|
|
23
|
+
refreshToken: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
declare class LoginUseCase extends BaseUseCase<LoginRequest, AuthTokens> {
|
|
27
|
+
private readonly authRepository;
|
|
28
|
+
private readonly authStore;
|
|
29
|
+
private readonly router;
|
|
30
|
+
private readonly urlRedirectService;
|
|
31
|
+
execute(request: LoginRequest): Observable<AuthTokens>;
|
|
32
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<LoginUseCase, never>;
|
|
33
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<LoginUseCase>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
declare class RegisterUseCase extends BaseUseCase<RegisterRequest, AuthTokens> {
|
|
37
|
+
private readonly authRepository;
|
|
38
|
+
private readonly authStore;
|
|
39
|
+
private readonly router;
|
|
40
|
+
execute(request: RegisterRequest): Observable<AuthTokens>;
|
|
41
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<RegisterUseCase, never>;
|
|
42
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<RegisterUseCase>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
declare class RefreshTokenUseCase extends BaseUseCase<void, AuthTokens> {
|
|
46
|
+
private readonly authRepository;
|
|
47
|
+
private readonly userRepository;
|
|
48
|
+
private readonly tokenRepository;
|
|
49
|
+
private readonly authStore;
|
|
50
|
+
execute(): Observable<AuthTokens>;
|
|
51
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<RefreshTokenUseCase, never>;
|
|
52
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<RefreshTokenUseCase>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
declare class LogoutUseCase extends BaseUseCase<void, void> {
|
|
56
|
+
private readonly authRepository;
|
|
57
|
+
private readonly userRepository;
|
|
58
|
+
private readonly tokenRepository;
|
|
59
|
+
private readonly authStore;
|
|
60
|
+
execute(): Observable<void>;
|
|
61
|
+
private cleanup;
|
|
62
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<LogoutUseCase, never>;
|
|
63
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<LogoutUseCase>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
declare abstract class AuthRepository {
|
|
67
|
+
abstract login(request: LoginRequest): Observable<AuthTokens>;
|
|
68
|
+
abstract register(request: RegisterRequest): Observable<AuthTokens>;
|
|
69
|
+
abstract refreshToken(request: RefreshTokenRequest): Observable<AuthTokens>;
|
|
70
|
+
abstract logout(email: string, refreshToken: string): Observable<void>;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
declare class AuthHttpRepository extends AuthRepository {
|
|
74
|
+
private readonly http;
|
|
75
|
+
private readonly URL;
|
|
76
|
+
login(request: LoginRequest): Observable<AuthTokens>;
|
|
77
|
+
register(request: RegisterRequest): Observable<AuthTokens>;
|
|
78
|
+
refreshToken(request: RefreshTokenRequest): Observable<AuthTokens>;
|
|
79
|
+
logout(email: string, refreshToken: string): Observable<void>;
|
|
80
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<AuthHttpRepository, never>;
|
|
81
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<AuthHttpRepository>;
|
|
82
|
+
}
|
|
83
|
+
|
|
11
84
|
declare const authGuard: CanActivateFn;
|
|
12
85
|
|
|
86
|
+
/**
|
|
87
|
+
* Interceptor that handles authentication errors and manages URL redirection
|
|
88
|
+
* Captures the current URL when a 401 error occurs and redirects to login
|
|
89
|
+
*/
|
|
90
|
+
declare const authRedirectInterceptor: HttpInterceptorFn;
|
|
91
|
+
|
|
92
|
+
declare const SKIP_CSRF: HttpContextToken<boolean>;
|
|
93
|
+
/**
|
|
94
|
+
* HTTP interceptor that automatically adds CSRF tokens to state-changing requests
|
|
95
|
+
* Only applies to requests to the same origin to avoid leaking tokens to external APIs
|
|
96
|
+
*/
|
|
97
|
+
declare const csrfInterceptor: HttpInterceptorFn;
|
|
98
|
+
|
|
99
|
+
declare const authProviders: Provider[];
|
|
100
|
+
|
|
101
|
+
declare class TokenRepository implements ITokenProvider {
|
|
102
|
+
private environment;
|
|
103
|
+
private platformId;
|
|
104
|
+
saveTokens(tokens: AuthTokens, rememberMe?: boolean): void;
|
|
105
|
+
getToken(): string | null;
|
|
106
|
+
getRefreshToken(): string | null;
|
|
107
|
+
setToken(token: string, rememberMe?: boolean): void;
|
|
108
|
+
setRefreshToken(refreshToken: string, rememberMe?: boolean): void;
|
|
109
|
+
clearTokens(): void;
|
|
110
|
+
isAuthenticated(): boolean;
|
|
111
|
+
needsRefresh(): boolean;
|
|
112
|
+
getTokenPayload(): unknown;
|
|
113
|
+
/**
|
|
114
|
+
* Determines if tokens are stored persistently (localStorage) vs session (sessionStorage)
|
|
115
|
+
*/
|
|
116
|
+
isRememberMeEnabled(): boolean;
|
|
117
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<TokenRepository, never>;
|
|
118
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<TokenRepository>;
|
|
119
|
+
}
|
|
120
|
+
|
|
13
121
|
/**
|
|
14
122
|
* Service to manage URL redirection after authentication
|
|
15
123
|
* Stores the intended URL when session is lost and redirects to it after successful login
|
|
@@ -65,104 +173,19 @@ declare class UrlRedirectService {
|
|
|
65
173
|
static ɵprov: i0.ɵɵInjectableDeclaration<UrlRedirectService>;
|
|
66
174
|
}
|
|
67
175
|
|
|
68
|
-
declare class
|
|
69
|
-
private
|
|
70
|
-
private
|
|
71
|
-
saveTokens(tokens: AuthTokens, rememberMe?: boolean): void;
|
|
72
|
-
getToken(): string | null;
|
|
73
|
-
getRefreshToken(): string | null;
|
|
74
|
-
setToken(token: string, rememberMe?: boolean): void;
|
|
75
|
-
setRefreshToken(refreshToken: string, rememberMe?: boolean): void;
|
|
76
|
-
clearTokens(): void;
|
|
77
|
-
isAuthenticated(): boolean;
|
|
78
|
-
needsRefresh(): boolean;
|
|
79
|
-
getTokenPayload(): unknown;
|
|
176
|
+
declare class CsrfService {
|
|
177
|
+
private http;
|
|
178
|
+
private csrfToken;
|
|
80
179
|
/**
|
|
81
|
-
*
|
|
180
|
+
* Get CSRF token, fetching it if not available
|
|
82
181
|
*/
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
* Captures the current URL when a 401 error occurs and redirects to login
|
|
91
|
-
*/
|
|
92
|
-
declare const authRedirectInterceptor: HttpInterceptorFn;
|
|
93
|
-
|
|
94
|
-
interface LoginRequest {
|
|
95
|
-
email: string;
|
|
96
|
-
password: string;
|
|
97
|
-
rememberMe?: boolean;
|
|
98
|
-
}
|
|
99
|
-
interface RegisterRequest {
|
|
100
|
-
email: string;
|
|
101
|
-
displayName: string;
|
|
102
|
-
password: string;
|
|
103
|
-
}
|
|
104
|
-
interface RefreshTokenRequest {
|
|
105
|
-
email: string;
|
|
106
|
-
refreshToken: string;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
declare abstract class AuthRepository {
|
|
110
|
-
abstract login(request: LoginRequest): Observable<AuthTokens>;
|
|
111
|
-
abstract register(request: RegisterRequest): Observable<AuthTokens>;
|
|
112
|
-
abstract refreshToken(request: RefreshTokenRequest): Observable<AuthTokens>;
|
|
113
|
-
abstract logout(email: string, refreshToken: string): Observable<void>;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
declare class AuthHttpRepository extends AuthRepository {
|
|
117
|
-
private readonly http;
|
|
118
|
-
private readonly csrfService;
|
|
119
|
-
private readonly URL;
|
|
120
|
-
login(request: LoginRequest): Observable<AuthTokens>;
|
|
121
|
-
register(request: RegisterRequest): Observable<AuthTokens>;
|
|
122
|
-
refreshToken(request: RefreshTokenRequest): Observable<AuthTokens>;
|
|
123
|
-
logout(email: string, refreshToken: string): Observable<void>;
|
|
124
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<AuthHttpRepository, never>;
|
|
125
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<AuthHttpRepository>;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
declare class LoginUseCase extends BaseUseCase<LoginRequest, AuthTokens> {
|
|
129
|
-
private readonly authRepository;
|
|
130
|
-
private readonly authStore;
|
|
131
|
-
private readonly router;
|
|
132
|
-
private readonly urlRedirectService;
|
|
133
|
-
execute(request: LoginRequest): Observable<AuthTokens>;
|
|
134
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<LoginUseCase, never>;
|
|
135
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<LoginUseCase>;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
declare class RegisterUseCase extends BaseUseCase<RegisterRequest, AuthTokens> {
|
|
139
|
-
private readonly authRepository;
|
|
140
|
-
private readonly authStore;
|
|
141
|
-
private readonly router;
|
|
142
|
-
execute(request: RegisterRequest): Observable<AuthTokens>;
|
|
143
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<RegisterUseCase, never>;
|
|
144
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<RegisterUseCase>;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
declare class RefreshTokenUseCase extends BaseUseCase<void, AuthTokens> {
|
|
148
|
-
private readonly authRepository;
|
|
149
|
-
private readonly userRepository;
|
|
150
|
-
private readonly tokenRepository;
|
|
151
|
-
private readonly authStore;
|
|
152
|
-
execute(): Observable<AuthTokens>;
|
|
153
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<RefreshTokenUseCase, never>;
|
|
154
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<RefreshTokenUseCase>;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
declare class LogoutUseCase extends BaseUseCase<void, void> {
|
|
158
|
-
private readonly authRepository;
|
|
159
|
-
private readonly userRepository;
|
|
160
|
-
private readonly tokenRepository;
|
|
161
|
-
private readonly authStore;
|
|
162
|
-
execute(): Observable<void>;
|
|
163
|
-
private cleanup;
|
|
164
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<LogoutUseCase, never>;
|
|
165
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<LogoutUseCase>;
|
|
182
|
+
getCsrfToken(): Promise<string>;
|
|
183
|
+
/**
|
|
184
|
+
* Clear stored CSRF token (useful on logout)
|
|
185
|
+
*/
|
|
186
|
+
clearCsrfToken(): void;
|
|
187
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<CsrfService, never>;
|
|
188
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<CsrfService>;
|
|
166
189
|
}
|
|
167
190
|
|
|
168
191
|
declare class AuthStore implements OnDestroy {
|
|
@@ -253,7 +276,5 @@ declare class LoginComponent implements OnInit {
|
|
|
253
276
|
static ɵcmp: i0.ɵɵComponentDeclaration<LoginComponent, "acp-login", never, { "title": { "alias": "title"; "required": false; "isSignal": true; }; "showRegisterButton": { "alias": "showRegisterButton"; "required": false; "isSignal": true; }; "showRememberMe": { "alias": "showRememberMe"; "required": false; "isSignal": true; }; "additionalSigninControls": { "alias": "additionalSigninControls"; "required": false; "isSignal": true; }; "additionalSignupControls": { "alias": "additionalSignupControls"; "required": false; "isSignal": true; }; "additionalSigninFields": { "alias": "additionalSigninFields"; "required": false; "isSignal": true; }; "additionalSignupFields": { "alias": "additionalSignupFields"; "required": false; "isSignal": true; }; "footerContent": { "alias": "footerContent"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
|
|
254
277
|
}
|
|
255
278
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
export { AuthHttpRepository, AuthRepository, AuthStore, LoginComponent, LoginUseCase, LogoutUseCase, RefreshTokenUseCase, RegisterUseCase, TokenRepository, UrlRedirectService, authGuard, authProviders, authRedirectInterceptor };
|
|
279
|
+
export { AuthHttpRepository, AuthRepository, AuthStore, CsrfService, LoginComponent, LoginUseCase, LogoutUseCase, RefreshTokenUseCase, RegisterUseCase, SKIP_CSRF, TokenRepository, UrlRedirectService, authGuard, authProviders, authRedirectInterceptor, csrfInterceptor };
|
|
259
280
|
export type { LoginRequest, RefreshTokenRequest, RegisterRequest };
|