@acontplus/ng-auth 1.1.1 → 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 +389 -363
- package/fesm2022/acontplus-ng-auth.mjs.map +1 -1
- package/index.d.ts +122 -109
- package/package.json +2 -2
package/index.d.ts
CHANGED
|
@@ -1,21 +1,121 @@
|
|
|
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
|
-
|
|
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
|
+
}
|
|
12
25
|
|
|
13
|
-
declare class
|
|
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;
|
|
14
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
|
+
|
|
84
|
+
declare const authGuard: CanActivateFn;
|
|
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;
|
|
15
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;
|
|
16
110
|
isAuthenticated(): boolean;
|
|
17
|
-
|
|
18
|
-
|
|
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>;
|
|
19
119
|
}
|
|
20
120
|
|
|
21
121
|
/**
|
|
@@ -73,104 +173,19 @@ declare class UrlRedirectService {
|
|
|
73
173
|
static ɵprov: i0.ɵɵInjectableDeclaration<UrlRedirectService>;
|
|
74
174
|
}
|
|
75
175
|
|
|
76
|
-
declare class
|
|
77
|
-
private
|
|
78
|
-
private
|
|
79
|
-
saveTokens(tokens: AuthTokens, rememberMe?: boolean): void;
|
|
80
|
-
getAccessToken(): string | null;
|
|
81
|
-
getRefreshToken(): string | null;
|
|
82
|
-
setToken(token: string, rememberMe?: boolean): void;
|
|
83
|
-
setRefreshToken(refreshToken: string, rememberMe?: boolean): void;
|
|
84
|
-
clearTokens(): void;
|
|
85
|
-
isAuthenticated(): boolean;
|
|
86
|
-
needsRefresh(): boolean;
|
|
87
|
-
getTokenPayload(): unknown;
|
|
176
|
+
declare class CsrfService {
|
|
177
|
+
private http;
|
|
178
|
+
private csrfToken;
|
|
88
179
|
/**
|
|
89
|
-
*
|
|
180
|
+
* Get CSRF token, fetching it if not available
|
|
90
181
|
*/
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
* Captures the current URL when a 401 error occurs and redirects to login
|
|
99
|
-
*/
|
|
100
|
-
declare const authRedirectInterceptor: HttpInterceptorFn;
|
|
101
|
-
|
|
102
|
-
interface LoginRequest {
|
|
103
|
-
email: string;
|
|
104
|
-
password: string;
|
|
105
|
-
rememberMe?: boolean;
|
|
106
|
-
}
|
|
107
|
-
interface RegisterRequest {
|
|
108
|
-
email: string;
|
|
109
|
-
displayName: string;
|
|
110
|
-
password: string;
|
|
111
|
-
}
|
|
112
|
-
interface RefreshTokenRequest {
|
|
113
|
-
email: string;
|
|
114
|
-
refreshToken: string;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
declare abstract class AuthRepository {
|
|
118
|
-
abstract login(request: LoginRequest): Observable<AuthTokens>;
|
|
119
|
-
abstract register(request: RegisterRequest): Observable<AuthTokens>;
|
|
120
|
-
abstract refreshToken(request: RefreshTokenRequest): Observable<AuthTokens>;
|
|
121
|
-
abstract logout(email: string, refreshToken: string): Observable<void>;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
declare class AuthHttpRepository extends AuthRepository {
|
|
125
|
-
private readonly http;
|
|
126
|
-
private readonly csrfService;
|
|
127
|
-
private readonly URL;
|
|
128
|
-
login(request: LoginRequest): Observable<AuthTokens>;
|
|
129
|
-
register(request: RegisterRequest): Observable<AuthTokens>;
|
|
130
|
-
refreshToken(request: RefreshTokenRequest): Observable<AuthTokens>;
|
|
131
|
-
logout(email: string, refreshToken: string): Observable<void>;
|
|
132
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<AuthHttpRepository, never>;
|
|
133
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<AuthHttpRepository>;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
declare class LoginUseCase extends BaseUseCase<LoginRequest, AuthTokens> {
|
|
137
|
-
private readonly authRepository;
|
|
138
|
-
private readonly authStore;
|
|
139
|
-
private readonly router;
|
|
140
|
-
private readonly urlRedirectService;
|
|
141
|
-
execute(request: LoginRequest): Observable<AuthTokens>;
|
|
142
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<LoginUseCase, never>;
|
|
143
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<LoginUseCase>;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
declare class RegisterUseCase extends BaseUseCase<RegisterRequest, AuthTokens> {
|
|
147
|
-
private readonly authRepository;
|
|
148
|
-
private readonly authStore;
|
|
149
|
-
private readonly router;
|
|
150
|
-
execute(request: RegisterRequest): Observable<AuthTokens>;
|
|
151
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<RegisterUseCase, never>;
|
|
152
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<RegisterUseCase>;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
declare class RefreshTokenUseCase extends BaseUseCase<void, AuthTokens> {
|
|
156
|
-
private readonly authRepository;
|
|
157
|
-
private readonly userRepository;
|
|
158
|
-
private readonly tokenRepository;
|
|
159
|
-
private readonly authStore;
|
|
160
|
-
execute(): Observable<AuthTokens>;
|
|
161
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<RefreshTokenUseCase, never>;
|
|
162
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<RefreshTokenUseCase>;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
declare class LogoutUseCase extends BaseUseCase<void, void> {
|
|
166
|
-
private readonly authRepository;
|
|
167
|
-
private readonly userRepository;
|
|
168
|
-
private readonly tokenRepository;
|
|
169
|
-
private readonly authStore;
|
|
170
|
-
execute(): Observable<void>;
|
|
171
|
-
private cleanup;
|
|
172
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<LogoutUseCase, never>;
|
|
173
|
-
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>;
|
|
174
189
|
}
|
|
175
190
|
|
|
176
191
|
declare class AuthStore implements OnDestroy {
|
|
@@ -261,7 +276,5 @@ declare class LoginComponent implements OnInit {
|
|
|
261
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>;
|
|
262
277
|
}
|
|
263
278
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
export { AuthHttpRepository, AuthRepository, AuthStore, AuthTokenService, 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 };
|
|
267
280
|
export type { LoginRequest, RefreshTokenRequest, RegisterRequest };
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acontplus/ng-auth",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "Acontplus Angular Authentication Module",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@acontplus/ng-infrastructure": "^1.0.
|
|
6
|
+
"@acontplus/ng-infrastructure": "^1.0.4",
|
|
7
7
|
"@acontplus/ng-config": "^1.0.3",
|
|
8
8
|
"jwt-decode": "^4.0.0",
|
|
9
9
|
"rxjs": "^7.8.1",
|