@verisoft/security-core 20.0.0 → 20.1.0
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/.eslintrc.json +48 -0
- package/jest.config.ts +21 -0
- package/ng-package.json +7 -0
- package/package.json +3 -17
- package/project.json +36 -0
- package/src/index.ts +1 -0
- package/src/lib/directives/has-permission.directive.ts +54 -0
- package/src/lib/directives/has-role.directive.ts +54 -0
- package/src/lib/directives/index.ts +2 -0
- package/src/lib/guards/auth.guard.ts +55 -0
- package/src/lib/guards/index.ts +1 -0
- package/src/lib/index.ts +6 -0
- package/src/lib/models/authenticated-user.model.ts +8 -0
- package/src/lib/models/config.model.ts +9 -0
- package/src/lib/models/functions.spec.ts +159 -0
- package/src/lib/models/functions.ts +103 -0
- package/src/lib/models/index.ts +3 -0
- package/src/lib/provider.ts +52 -0
- package/src/lib/services/auth-context.service.ts +38 -0
- package/src/lib/services/index.ts +7 -0
- package/src/lib/services/local-storage-token-provider.ts +23 -0
- package/src/lib/services/local-token-provider.ts +15 -0
- package/src/lib/services/login.service.ts +23 -0
- package/src/lib/services/logout.service.ts +15 -0
- package/src/lib/services/security-initializer.ts +26 -0
- package/src/lib/services/session-token-provider.ts +15 -0
- package/src/lib/services/token-provider.ts +5 -0
- package/src/lib/state/actions.ts +7 -0
- package/src/lib/state/feature.ts +10 -0
- package/src/lib/state/index.ts +4 -0
- package/src/lib/state/reducers.ts +11 -0
- package/src/lib/state/selectors.ts +9 -0
- package/src/lib/state/state.ts +9 -0
- package/src/test-setup.ts +8 -0
- package/tsconfig.json +28 -0
- package/tsconfig.lib.json +17 -0
- package/tsconfig.lib.prod.json +9 -0
- package/tsconfig.spec.json +16 -0
- package/fesm2022/verisoft-security-core.mjs +0 -380
- package/fesm2022/verisoft-security-core.mjs.map +0 -1
- package/index.d.ts +0 -153
package/index.d.ts
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import * as i0 from '@angular/core';
|
|
2
|
-
import { OnDestroy, TemplateRef, ViewContainerRef, Provider, EnvironmentProviders, ModuleWithProviders, InjectionToken } from '@angular/core';
|
|
3
|
-
import * as _ngrx_store from '@ngrx/store';
|
|
4
|
-
import { Store } from '@ngrx/store';
|
|
5
|
-
import { Observable } from 'rxjs';
|
|
6
|
-
import { Router, CanActivate, CanActivateChild, ActivatedRouteSnapshot, UrlTree } from '@angular/router';
|
|
7
|
-
import * as _verisoft_security_core from '@verisoft/security-core';
|
|
8
|
-
|
|
9
|
-
interface AuthenticatedUser {
|
|
10
|
-
userId?: string;
|
|
11
|
-
userName: string;
|
|
12
|
-
email: string;
|
|
13
|
-
displayName?: string;
|
|
14
|
-
roles: string[] | undefined;
|
|
15
|
-
permissions: string[] | undefined;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
declare function hasRequiredPermission(user: AuthenticatedUser | undefined, permission: string | string[]): boolean;
|
|
19
|
-
declare function hasRequiredRole(user: AuthenticatedUser | undefined, role: string | string[]): boolean;
|
|
20
|
-
declare function convertJWTToUser(base64Token?: string): AuthenticatedUser | undefined;
|
|
21
|
-
declare function decodeJwtPayload(jwt: string): any;
|
|
22
|
-
|
|
23
|
-
interface SecurityConfig {
|
|
24
|
-
tokenStorageKey: string;
|
|
25
|
-
contextTokenStorageKey?: string;
|
|
26
|
-
loginPage?: string;
|
|
27
|
-
logoutPage?: string;
|
|
28
|
-
notAuthorizedPage?: string;
|
|
29
|
-
sendTokenHeader?: boolean;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
declare class AuthContextService {
|
|
33
|
-
private store;
|
|
34
|
-
user$: Observable<AuthenticatedUser | undefined>;
|
|
35
|
-
isAuthenticated$: Observable<boolean>;
|
|
36
|
-
constructor(store: Store);
|
|
37
|
-
setUser(user: AuthenticatedUser | undefined): void;
|
|
38
|
-
hasRequiredPermission(requiredPermissions: string | string[]): Observable<boolean>;
|
|
39
|
-
hasRequiredRole(requiredPermissions: string | string[]): Observable<boolean>;
|
|
40
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<AuthContextService, never>;
|
|
41
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<AuthContextService>;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
interface TokenProvider {
|
|
45
|
-
getToken(): Observable<string | undefined>;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
declare class LocalStorageTokenProvider implements TokenProvider {
|
|
49
|
-
private config;
|
|
50
|
-
getToken(): Observable<string | undefined>;
|
|
51
|
-
setToken(token: string): void;
|
|
52
|
-
removeToken(): void;
|
|
53
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<LocalStorageTokenProvider, never>;
|
|
54
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<LocalStorageTokenProvider>;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
declare function securityInitializerFactory(tokenProvider: TokenProvider, authService: AuthContextService, config: SecurityConfig, router: Router): () => Promise<unknown>;
|
|
58
|
-
|
|
59
|
-
declare class SessionStorageTokenProvider implements TokenProvider {
|
|
60
|
-
private config;
|
|
61
|
-
getToken(): Observable<string | undefined>;
|
|
62
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<SessionStorageTokenProvider, never>;
|
|
63
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<SessionStorageTokenProvider>;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
declare class LoginService {
|
|
67
|
-
private config;
|
|
68
|
-
private tokenProvider;
|
|
69
|
-
private authService;
|
|
70
|
-
private router;
|
|
71
|
-
login(token?: string): void;
|
|
72
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<LoginService, never>;
|
|
73
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<LoginService>;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
declare class LogoutService {
|
|
77
|
-
private readonly tokenProvider;
|
|
78
|
-
private readonly authService;
|
|
79
|
-
logout(): void;
|
|
80
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<LogoutService, never>;
|
|
81
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<LogoutService>;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
declare class HasPermissionDirective<T> implements OnDestroy {
|
|
85
|
-
private templateRef;
|
|
86
|
-
private viewContainer;
|
|
87
|
-
private authContext;
|
|
88
|
-
private requiredPermissions;
|
|
89
|
-
private sub?;
|
|
90
|
-
constructor(templateRef: TemplateRef<T>, viewContainer: ViewContainerRef, authContext: AuthContextService);
|
|
91
|
-
set hasPermission(value: string | string[]);
|
|
92
|
-
ngOnDestroy(): void;
|
|
93
|
-
private unregister;
|
|
94
|
-
private updateView;
|
|
95
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<HasPermissionDirective<any>, never>;
|
|
96
|
-
static ɵdir: i0.ɵɵDirectiveDeclaration<HasPermissionDirective<any>, "[hasPermission]", never, { "hasPermission": { "alias": "hasPermission"; "required": false; }; }, {}, never, never, true, never>;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
declare class HasRoleDirective<T> implements OnDestroy {
|
|
100
|
-
private templateRef;
|
|
101
|
-
private viewContainer;
|
|
102
|
-
private authContext;
|
|
103
|
-
private requiredRoles;
|
|
104
|
-
private sub?;
|
|
105
|
-
constructor(templateRef: TemplateRef<T>, viewContainer: ViewContainerRef, authContext: AuthContextService);
|
|
106
|
-
set hasRole(value: string | string[]);
|
|
107
|
-
ngOnDestroy(): void;
|
|
108
|
-
private unregister;
|
|
109
|
-
private updateView;
|
|
110
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<HasRoleDirective<any>, never>;
|
|
111
|
-
static ɵdir: i0.ɵɵDirectiveDeclaration<HasRoleDirective<any>, "[hasRole]", never, { "hasRole": { "alias": "hasRole"; "required": false; }; }, {}, never, never, true, never>;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
declare class AuthGuard implements CanActivate, CanActivateChild {
|
|
115
|
-
private config;
|
|
116
|
-
private router;
|
|
117
|
-
private authContext;
|
|
118
|
-
canActivate(route: ActivatedRouteSnapshot): Observable<boolean | UrlTree>;
|
|
119
|
-
canActivateChild(childRoute: ActivatedRouteSnapshot): Observable<boolean | UrlTree>;
|
|
120
|
-
private checkPermissionsAndRolesAndNavigate;
|
|
121
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<AuthGuard, never>;
|
|
122
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<AuthGuard>;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
declare const setUser: _ngrx_store.ActionCreator<"[Auth] Set User", (props: {
|
|
126
|
-
user: AuthenticatedUser | undefined;
|
|
127
|
-
}) => {
|
|
128
|
-
user: AuthenticatedUser | undefined;
|
|
129
|
-
} & _ngrx_store.Action<"[Auth] Set User">>;
|
|
130
|
-
|
|
131
|
-
interface AuthState {
|
|
132
|
-
user: AuthenticatedUser | undefined;
|
|
133
|
-
}
|
|
134
|
-
declare const initialState: AuthState;
|
|
135
|
-
|
|
136
|
-
declare const authReducer: _ngrx_store.ActionReducer<AuthState, _ngrx_store.Action<string>>;
|
|
137
|
-
|
|
138
|
-
declare const selectIsAuthenticated: _ngrx_store.MemoizedSelector<Record<string, any>, boolean, (s1: _verisoft_security_core.AuthenticatedUser | undefined) => boolean>;
|
|
139
|
-
declare const selectUser: _ngrx_store.MemoizedSelector<Record<string, any>, _verisoft_security_core.AuthenticatedUser | undefined, (featureState: _verisoft_security_core.AuthState) => _verisoft_security_core.AuthenticatedUser | undefined>;
|
|
140
|
-
|
|
141
|
-
declare function provideSecurity(config?: Partial<SecurityConfig> | undefined): (Provider | EnvironmentProviders)[];
|
|
142
|
-
declare class SecurityModule {
|
|
143
|
-
static forRoot(config?: Partial<SecurityConfig>): ModuleWithProviders<SecurityModule>;
|
|
144
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<SecurityModule, never>;
|
|
145
|
-
static ɵmod: i0.ɵɵNgModuleDeclaration<SecurityModule, never, [typeof _ngrx_store.StoreFeatureModule], never>;
|
|
146
|
-
static ɵinj: i0.ɵɵInjectorDeclaration<SecurityModule>;
|
|
147
|
-
}
|
|
148
|
-
declare const SECURITY_CONTEXT_TOKEN_PROVIDER: InjectionToken<unknown>;
|
|
149
|
-
declare const SECURITY_CONFIG: InjectionToken<unknown>;
|
|
150
|
-
declare const SECURITY_INITIALIZER_PROVIDER: EnvironmentProviders;
|
|
151
|
-
|
|
152
|
-
export { AuthContextService, AuthGuard, HasPermissionDirective, HasRoleDirective, LocalStorageTokenProvider, LoginService, LogoutService, SECURITY_CONFIG, SECURITY_CONTEXT_TOKEN_PROVIDER, SECURITY_INITIALIZER_PROVIDER, SecurityModule, SessionStorageTokenProvider, authReducer, convertJWTToUser, decodeJwtPayload, hasRequiredPermission, hasRequiredRole, initialState, provideSecurity, securityInitializerFactory, selectIsAuthenticated, selectUser, setUser };
|
|
153
|
-
export type { AuthState, AuthenticatedUser, SecurityConfig, TokenProvider };
|