@archbase/security 3.0.0 → 3.0.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/LICENSE +21 -0
- package/README.md +51 -0
- package/dist/index.d.ts +2 -0
- package/dist/src/ArchbaseAccessToken.d.ts +1 -0
- package/dist/src/ArchbaseAccessTokenService.d.ts +11 -0
- package/dist/src/ArchbaseApiTokenService.d.ts +12 -0
- package/dist/src/ArchbaseAuthenticator.d.ts +24 -0
- package/dist/src/ArchbaseGroupService.d.ts +10 -0
- package/dist/src/ArchbaseLogin.d.ts +30 -0
- package/dist/src/ArchbaseProfileService.d.ts +10 -0
- package/dist/src/ArchbaseResetPassword.d.ts +14 -0
- package/dist/src/ArchbaseResourceService.d.ts +16 -0
- package/dist/src/ArchbaseSecurityComponents.d.ts +40 -0
- package/dist/src/ArchbaseSecurityContext.d.ts +41 -0
- package/dist/src/ArchbaseSecurityHooks.d.ts +24 -0
- package/dist/src/ArchbaseSecurityManager.d.ts +58 -0
- package/dist/src/ArchbaseTenantManager.d.ts +22 -0
- package/dist/src/ArchbaseTokenManager.d.ts +1 -0
- package/dist/src/ArchbaseUser.d.ts +19 -0
- package/dist/src/ArchbaseUserService.d.ts +11 -0
- package/dist/src/DefaultArchbaseTokenManager.d.ts +20 -0
- package/dist/src/SecurityDomain.d.ts +221 -0
- package/dist/src/SecurityType.d.ts +5 -0
- package/dist/src/examples/ContextualAuthenticationExample.d.ts +113 -0
- package/dist/src/examples/SecurityExample.d.ts +2 -0
- package/dist/src/hooks/index.d.ts +5 -0
- package/dist/src/hooks/useArchbaseAuthenticationManager.d.ts +36 -0
- package/dist/src/hooks/useArchbaseGetCurrentToken.d.ts +4 -0
- package/dist/src/hooks/useArchbaseGetLoggedUser.d.ts +2 -0
- package/dist/src/hooks/useArchbaseResetPassword.d.ts +8 -0
- package/dist/src/hooks/useArchbaseSecurityManager.d.ts +11 -0
- package/dist/src/index.d.ts +27 -0
- package/dist/src/oauth2/AuthContext.d.ts +4 -0
- package/dist/src/oauth2/Types.d.ts +108 -0
- package/dist/src/oauth2/authConfig.d.ts +3 -0
- package/dist/src/oauth2/authentication.d.ts +9 -0
- package/dist/src/oauth2/decodeJWT.d.ts +5 -0
- package/dist/src/oauth2/errors.d.ts +5 -0
- package/dist/src/oauth2/hooks.d.ts +2 -0
- package/dist/src/oauth2/httpUtils.d.ts +2 -0
- package/dist/src/oauth2/index.d.ts +10 -0
- package/dist/src/oauth2/pkceUtils.d.ts +6 -0
- package/dist/src/oauth2/timeUtils.d.ts +9 -0
- package/dist/src/types/ArchbaseSecurityTypes.d.ts +50 -0
- package/dist/src/types/ContextualAuthentication.d.ts +160 -0
- package/package.json +23 -22
- package/dist/archbase-security-3.0.0.tgz +0 -0
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
export declare enum TipoRecurso {
|
|
2
|
+
VIEW = "VIEW",
|
|
3
|
+
API = "API"
|
|
4
|
+
}
|
|
5
|
+
export declare class AccessScheduleDto {
|
|
6
|
+
id: string;
|
|
7
|
+
code: string;
|
|
8
|
+
version: number;
|
|
9
|
+
createEntityDate: string;
|
|
10
|
+
updateEntityDate: string;
|
|
11
|
+
createdByUser: string;
|
|
12
|
+
lastModifiedByUser: string;
|
|
13
|
+
description: string;
|
|
14
|
+
intervals: AccessIntervalDto[];
|
|
15
|
+
constructor(data: any);
|
|
16
|
+
static newInstance: () => AccessScheduleDto;
|
|
17
|
+
}
|
|
18
|
+
export declare class AccessIntervalDto {
|
|
19
|
+
id: string;
|
|
20
|
+
code: string;
|
|
21
|
+
version: number;
|
|
22
|
+
createEntityDate: string;
|
|
23
|
+
updateEntityDate: string;
|
|
24
|
+
createdByUser: string;
|
|
25
|
+
lastModifiedByUser: string;
|
|
26
|
+
accessSchedule?: AccessScheduleDto;
|
|
27
|
+
dayOfWeek: number;
|
|
28
|
+
startTime: string;
|
|
29
|
+
endTime: string;
|
|
30
|
+
constructor(data: any);
|
|
31
|
+
static newInstance: () => AccessIntervalDto;
|
|
32
|
+
}
|
|
33
|
+
export declare abstract class SecurityDto {
|
|
34
|
+
id: string;
|
|
35
|
+
code: string;
|
|
36
|
+
version: number;
|
|
37
|
+
createEntityDate: string;
|
|
38
|
+
updateEntityDate: string;
|
|
39
|
+
createdByUser: string;
|
|
40
|
+
lastModifiedByUser: string;
|
|
41
|
+
name: string;
|
|
42
|
+
description: string;
|
|
43
|
+
actions: ActionDto[];
|
|
44
|
+
constructor(data: any);
|
|
45
|
+
}
|
|
46
|
+
export declare class ActionDto {
|
|
47
|
+
id: string;
|
|
48
|
+
code: string;
|
|
49
|
+
version: number;
|
|
50
|
+
createEntityDate: string;
|
|
51
|
+
updateEntityDate: string;
|
|
52
|
+
createdByUser: string;
|
|
53
|
+
lastModifiedByUser: string;
|
|
54
|
+
name: string;
|
|
55
|
+
description: string;
|
|
56
|
+
resource?: ResourceDto;
|
|
57
|
+
category: string;
|
|
58
|
+
active: boolean;
|
|
59
|
+
actionVersion: string;
|
|
60
|
+
isNewAction: boolean;
|
|
61
|
+
constructor(data: any);
|
|
62
|
+
static newInstance: () => ActionDto;
|
|
63
|
+
}
|
|
64
|
+
export declare class ProfileDto extends SecurityDto {
|
|
65
|
+
type: string;
|
|
66
|
+
isNewProfile: boolean;
|
|
67
|
+
constructor(data: any);
|
|
68
|
+
static newInstance: () => ProfileDto;
|
|
69
|
+
}
|
|
70
|
+
export declare class UserGroupDto {
|
|
71
|
+
id: string;
|
|
72
|
+
code: string;
|
|
73
|
+
version: number;
|
|
74
|
+
createEntityDate: string;
|
|
75
|
+
updateEntityDate: string;
|
|
76
|
+
createdByUser: string;
|
|
77
|
+
lastModifiedByUser: string;
|
|
78
|
+
group?: GroupDto;
|
|
79
|
+
constructor(data: any);
|
|
80
|
+
static newInstance: (group: GroupDto) => UserGroupDto;
|
|
81
|
+
}
|
|
82
|
+
export declare class GroupDto extends SecurityDto {
|
|
83
|
+
type: string;
|
|
84
|
+
isNewGroup: boolean;
|
|
85
|
+
constructor(data: any);
|
|
86
|
+
static newInstance: () => GroupDto;
|
|
87
|
+
}
|
|
88
|
+
export declare class ResourceDto {
|
|
89
|
+
id: string;
|
|
90
|
+
code: string;
|
|
91
|
+
version: number;
|
|
92
|
+
createEntityDate: string;
|
|
93
|
+
updateEntityDate: string;
|
|
94
|
+
createdByUser: string;
|
|
95
|
+
lastModifiedByUser: string;
|
|
96
|
+
name: string;
|
|
97
|
+
description: string;
|
|
98
|
+
actions: ActionDto[];
|
|
99
|
+
active: boolean;
|
|
100
|
+
type: TipoRecurso;
|
|
101
|
+
isNewResource: boolean;
|
|
102
|
+
constructor(data: any);
|
|
103
|
+
static newInstance: () => ResourceDto;
|
|
104
|
+
}
|
|
105
|
+
export declare class UserDto extends SecurityDto {
|
|
106
|
+
userName: string;
|
|
107
|
+
password: string;
|
|
108
|
+
changePasswordOnNextLogin: boolean;
|
|
109
|
+
allowPasswordChange: boolean;
|
|
110
|
+
allowMultipleLogins: boolean;
|
|
111
|
+
passwordNeverExpires: boolean;
|
|
112
|
+
accountDeactivated: boolean;
|
|
113
|
+
accountLocked: boolean;
|
|
114
|
+
unlimitedAccessHours: boolean;
|
|
115
|
+
isAdministrator: boolean;
|
|
116
|
+
accessSchedule?: AccessScheduleDto;
|
|
117
|
+
groups: UserGroupDto[];
|
|
118
|
+
profile?: ProfileDto;
|
|
119
|
+
avatar?: string;
|
|
120
|
+
nickname: string;
|
|
121
|
+
email?: string;
|
|
122
|
+
type: string;
|
|
123
|
+
isNewUser: boolean;
|
|
124
|
+
constructor(data: any);
|
|
125
|
+
static newInstance: () => UserDto;
|
|
126
|
+
}
|
|
127
|
+
export declare class PermissionDto {
|
|
128
|
+
id: string;
|
|
129
|
+
code: string;
|
|
130
|
+
version: number;
|
|
131
|
+
createEntityDate: string;
|
|
132
|
+
updateEntityDate: string;
|
|
133
|
+
createdByUser: string;
|
|
134
|
+
lastModifiedByUser: string;
|
|
135
|
+
security?: SecurityDto;
|
|
136
|
+
action?: ActionDto;
|
|
137
|
+
tenantId: string;
|
|
138
|
+
companyId: string;
|
|
139
|
+
projectId: string;
|
|
140
|
+
constructor(data: any);
|
|
141
|
+
static createDtoFromJson(data: any): SecurityDto;
|
|
142
|
+
static newInstance: () => PermissionDto;
|
|
143
|
+
}
|
|
144
|
+
export declare class ApiTokenDto {
|
|
145
|
+
id: string;
|
|
146
|
+
code: string;
|
|
147
|
+
version: number;
|
|
148
|
+
createEntityDate: string;
|
|
149
|
+
updateEntityDate: string;
|
|
150
|
+
createdByUser: string;
|
|
151
|
+
lastModifiedByUser: string;
|
|
152
|
+
tenantId: string;
|
|
153
|
+
name: string;
|
|
154
|
+
description: string;
|
|
155
|
+
token: string;
|
|
156
|
+
user: UserDto;
|
|
157
|
+
expirationDate: string;
|
|
158
|
+
revoked: boolean;
|
|
159
|
+
activated: boolean;
|
|
160
|
+
isNovoToken: boolean;
|
|
161
|
+
constructor(data: any);
|
|
162
|
+
static newInstance: () => ApiTokenDto;
|
|
163
|
+
}
|
|
164
|
+
export declare class AccessTokenDto {
|
|
165
|
+
id: string;
|
|
166
|
+
code: string;
|
|
167
|
+
version: number;
|
|
168
|
+
createEntityDate: string;
|
|
169
|
+
updateEntityDate: string;
|
|
170
|
+
createdByUser: string;
|
|
171
|
+
lastModifiedByUser: string;
|
|
172
|
+
token: string;
|
|
173
|
+
tokenType: string;
|
|
174
|
+
revoked: boolean;
|
|
175
|
+
expired: boolean;
|
|
176
|
+
expirationTime: number;
|
|
177
|
+
expirationDate: string;
|
|
178
|
+
user: UserDto;
|
|
179
|
+
isNewAccessToken: boolean;
|
|
180
|
+
constructor(data: any);
|
|
181
|
+
static newInstance: () => AccessTokenDto;
|
|
182
|
+
}
|
|
183
|
+
export interface GrantPermissionDto {
|
|
184
|
+
securityId: string;
|
|
185
|
+
actionId: string;
|
|
186
|
+
type: string;
|
|
187
|
+
}
|
|
188
|
+
export interface PermissionWithTypesDto {
|
|
189
|
+
permissionId?: string;
|
|
190
|
+
actionId: string;
|
|
191
|
+
actionDescription: string;
|
|
192
|
+
types?: string[];
|
|
193
|
+
}
|
|
194
|
+
export interface ResoucePermissionsWithTypeDto {
|
|
195
|
+
resourceId: string;
|
|
196
|
+
resourceDescription: string;
|
|
197
|
+
permissions: PermissionWithTypesDto[];
|
|
198
|
+
}
|
|
199
|
+
export interface ResouceActionPermissionDto {
|
|
200
|
+
resourceId: string;
|
|
201
|
+
resourceDescription: string;
|
|
202
|
+
permissionId: string;
|
|
203
|
+
actionId: string;
|
|
204
|
+
actionDescription: string;
|
|
205
|
+
}
|
|
206
|
+
export interface SimpleActionDto {
|
|
207
|
+
actionName: string;
|
|
208
|
+
actionDescription: string;
|
|
209
|
+
}
|
|
210
|
+
export interface SimpleResourceDto {
|
|
211
|
+
resourceName: string;
|
|
212
|
+
resourceDescription: string;
|
|
213
|
+
}
|
|
214
|
+
export interface ResourceRegisterDto {
|
|
215
|
+
resource: SimpleResourceDto;
|
|
216
|
+
actions: SimpleActionDto[];
|
|
217
|
+
}
|
|
218
|
+
export interface ResourcePermissionsDto {
|
|
219
|
+
resourceName: string;
|
|
220
|
+
permissions: string[];
|
|
221
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { ArchbaseAuthenticator, ArchbaseAccessToken, ContextualAuthenticationRequest, ContextualAuthenticationResponse, FlexibleLoginRequest, SocialLoginRequest, RegisterUserRequest } from '@archbase/security';
|
|
2
|
+
/**
|
|
3
|
+
* Exemplo de implementação de um ArchbaseAuthenticator com métodos contextuais opcionais
|
|
4
|
+
*/
|
|
5
|
+
export declare class ExampleContextualAuthenticator implements ArchbaseAuthenticator {
|
|
6
|
+
login(username: string, password: string): Promise<ArchbaseAccessToken>;
|
|
7
|
+
refreshToken(refresh_token: string): Promise<ArchbaseAccessToken>;
|
|
8
|
+
sendResetPasswordEmail(email: string): Promise<void>;
|
|
9
|
+
resetPassword(email: string, passwordResetToken: string, newPassword: string): Promise<void>;
|
|
10
|
+
loginWithContext(request: ContextualAuthenticationRequest): Promise<{
|
|
11
|
+
access_token: string;
|
|
12
|
+
refresh_token: string;
|
|
13
|
+
expires_in: number;
|
|
14
|
+
id_token: string;
|
|
15
|
+
token_type: string;
|
|
16
|
+
user: {
|
|
17
|
+
id: {
|
|
18
|
+
identifier: string;
|
|
19
|
+
};
|
|
20
|
+
name: string;
|
|
21
|
+
description: string;
|
|
22
|
+
userName: string;
|
|
23
|
+
email: string;
|
|
24
|
+
createEntityDate: string;
|
|
25
|
+
version: number;
|
|
26
|
+
changePasswordOnNextLogin: boolean;
|
|
27
|
+
allowPasswordChange: boolean;
|
|
28
|
+
allowMultipleLogins: boolean;
|
|
29
|
+
passwordNeverExpires: boolean;
|
|
30
|
+
accountDeactivated: boolean;
|
|
31
|
+
accountLocked: boolean;
|
|
32
|
+
unlimitedAccessHours: boolean;
|
|
33
|
+
isAdministrator: boolean;
|
|
34
|
+
groups: any[];
|
|
35
|
+
profile: any;
|
|
36
|
+
avatar: any;
|
|
37
|
+
nickname: any;
|
|
38
|
+
};
|
|
39
|
+
context: {
|
|
40
|
+
type: any;
|
|
41
|
+
adminId: string;
|
|
42
|
+
name: string;
|
|
43
|
+
email: string;
|
|
44
|
+
profilePicture: any;
|
|
45
|
+
accessLevel: string;
|
|
46
|
+
availableModules: string[];
|
|
47
|
+
status: string;
|
|
48
|
+
};
|
|
49
|
+
}>;
|
|
50
|
+
loginFlexible(request: FlexibleLoginRequest): Promise<{
|
|
51
|
+
access_token: string;
|
|
52
|
+
refresh_token: string;
|
|
53
|
+
expires_in: number;
|
|
54
|
+
id_token: string;
|
|
55
|
+
token_type: string;
|
|
56
|
+
user: {
|
|
57
|
+
id: {
|
|
58
|
+
identifier: string;
|
|
59
|
+
};
|
|
60
|
+
name: string;
|
|
61
|
+
description: string;
|
|
62
|
+
userName: string;
|
|
63
|
+
email: string;
|
|
64
|
+
createEntityDate: string;
|
|
65
|
+
version: number;
|
|
66
|
+
changePasswordOnNextLogin: boolean;
|
|
67
|
+
allowPasswordChange: boolean;
|
|
68
|
+
allowMultipleLogins: boolean;
|
|
69
|
+
passwordNeverExpires: boolean;
|
|
70
|
+
accountDeactivated: boolean;
|
|
71
|
+
accountLocked: boolean;
|
|
72
|
+
unlimitedAccessHours: boolean;
|
|
73
|
+
isAdministrator: boolean;
|
|
74
|
+
groups: any[];
|
|
75
|
+
profile: any;
|
|
76
|
+
avatar: any;
|
|
77
|
+
nickname: any;
|
|
78
|
+
};
|
|
79
|
+
context: {
|
|
80
|
+
type: any;
|
|
81
|
+
adminId: string;
|
|
82
|
+
name: string;
|
|
83
|
+
email: string;
|
|
84
|
+
profilePicture: any;
|
|
85
|
+
accessLevel: string;
|
|
86
|
+
availableModules: string[];
|
|
87
|
+
status: string;
|
|
88
|
+
};
|
|
89
|
+
}>;
|
|
90
|
+
loginSocial(request: SocialLoginRequest): Promise<ContextualAuthenticationResponse>;
|
|
91
|
+
register(request: RegisterUserRequest): Promise<{
|
|
92
|
+
email: any;
|
|
93
|
+
businessId: string;
|
|
94
|
+
message: string;
|
|
95
|
+
}>;
|
|
96
|
+
getSupportedContexts(): Promise<{
|
|
97
|
+
supportedContexts: string[];
|
|
98
|
+
defaultContext: string;
|
|
99
|
+
}>;
|
|
100
|
+
validateContext(context: string): Promise<{
|
|
101
|
+
context: string;
|
|
102
|
+
supported: boolean;
|
|
103
|
+
}>;
|
|
104
|
+
private resolveEmailFromIdentifier;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Exemplo de uso do hook com recursos contextuais
|
|
108
|
+
*/
|
|
109
|
+
export declare function ExampleUsageComponent(): any;
|
|
110
|
+
/**
|
|
111
|
+
* Exemplo de como verificar capacidades antes de usar
|
|
112
|
+
*/
|
|
113
|
+
export declare function CapabilitiesExample(): any;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ContextualAuthenticationRequest, FlexibleLoginRequest, SocialLoginRequest, RegisterUserRequest, SupportedContextsResponse, ContextValidationResponse, ContextObject } from '../types/ContextualAuthentication';
|
|
2
|
+
export interface AuthenticationManagerReturnType {
|
|
3
|
+
login: (username: string, password: string, rememberMe: boolean) => void;
|
|
4
|
+
logout: (clearRememberMe?: boolean) => void;
|
|
5
|
+
username: string;
|
|
6
|
+
isAuthenticating: boolean;
|
|
7
|
+
isInitializing: boolean;
|
|
8
|
+
isAuthenticated: boolean;
|
|
9
|
+
isError: boolean;
|
|
10
|
+
error: any;
|
|
11
|
+
clearError: () => void;
|
|
12
|
+
accessToken?: string | null;
|
|
13
|
+
loginWithContext?: (request: ContextualAuthenticationRequest, rememberMe?: boolean) => Promise<void>;
|
|
14
|
+
loginFlexible?: (request: FlexibleLoginRequest, rememberMe?: boolean) => Promise<void>;
|
|
15
|
+
loginSocial?: (request: SocialLoginRequest) => Promise<void>;
|
|
16
|
+
register?: (request: RegisterUserRequest) => Promise<{
|
|
17
|
+
email: string;
|
|
18
|
+
businessId?: string;
|
|
19
|
+
message: string;
|
|
20
|
+
}>;
|
|
21
|
+
getSupportedContexts?: () => Promise<SupportedContextsResponse>;
|
|
22
|
+
validateContext?: (context: string) => Promise<ContextValidationResponse>;
|
|
23
|
+
context?: ContextObject | null;
|
|
24
|
+
capabilities: {
|
|
25
|
+
hasContextualLogin: boolean;
|
|
26
|
+
hasFlexibleLogin: boolean;
|
|
27
|
+
hasSocialLogin: boolean;
|
|
28
|
+
hasRegistration: boolean;
|
|
29
|
+
hasContextSupport: boolean;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export interface ArchbaseAuthenticationManagerProps {
|
|
33
|
+
checkIntervalTokenHasExpired?: number;
|
|
34
|
+
expirationThresholdOfToken?: number;
|
|
35
|
+
}
|
|
36
|
+
export declare const useArchbaseAuthenticationManager: ({ checkIntervalTokenHasExpired, expirationThresholdOfToken }: ArchbaseAuthenticationManagerProps) => AuthenticationManagerReturnType;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface ResetPasswordReturnType {
|
|
2
|
+
sendResetPasswordEmail: (email: string) => Promise<void>;
|
|
3
|
+
resetPassword: (email: string, passwordResetToken: string, newPassword: string) => Promise<void>;
|
|
4
|
+
isError: boolean;
|
|
5
|
+
error: any;
|
|
6
|
+
clearError: () => void;
|
|
7
|
+
}
|
|
8
|
+
export declare const useArchbaseResetPassword: () => ResetPasswordReturnType;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ArchbaseSecurityManager } from '../ArchbaseSecurityManager';
|
|
2
|
+
export declare const ARCHBASE_SECURITY_MANAGER_STORE = "archbaseSecurityManagerStore";
|
|
3
|
+
export type UseArchbaseSecurityManagerProps = {
|
|
4
|
+
resourceName: string;
|
|
5
|
+
resourceDescription: string;
|
|
6
|
+
enableSecurity?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export type UseArchbaseSecurityManagerReturnType = {
|
|
9
|
+
securityManager: ArchbaseSecurityManager;
|
|
10
|
+
};
|
|
11
|
+
export declare const useArchbaseSecurityManager: ({ resourceName, resourceDescription, enableSecurity }: UseArchbaseSecurityManagerProps) => UseArchbaseSecurityManagerReturnType;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export * from './ArchbaseAccessToken';
|
|
2
|
+
export * from './ArchbaseAuthenticator';
|
|
3
|
+
export * from './ArchbaseTokenManager';
|
|
4
|
+
export * from './ArchbaseUser';
|
|
5
|
+
export * from './DefaultArchbaseTokenManager';
|
|
6
|
+
export * from './types/ContextualAuthentication';
|
|
7
|
+
export * from './oauth2';
|
|
8
|
+
export * from './ArchbaseSecurityManager';
|
|
9
|
+
export * from './ArchbaseTenantManager';
|
|
10
|
+
export * from './ArchbaseUserService';
|
|
11
|
+
export * from './ArchbaseGroupService';
|
|
12
|
+
export * from './ArchbaseProfileService';
|
|
13
|
+
export * from './ArchbaseApiTokenService';
|
|
14
|
+
export * from './ArchbaseAccessTokenService';
|
|
15
|
+
export * from './ArchbaseResourceService';
|
|
16
|
+
export * from './ArchbaseLogin';
|
|
17
|
+
export * from './ArchbaseResetPassword';
|
|
18
|
+
export * from './SecurityType';
|
|
19
|
+
export * from './SecurityDomain';
|
|
20
|
+
export * from './hooks';
|
|
21
|
+
export { ArchbaseSecurityProvider, ArchbaseViewSecurityProvider } from './ArchbaseSecurityContext';
|
|
22
|
+
export { useArchbaseSecurity, useArchbaseViewSecurity, useArchbaseSecureForm, useArchbasePermissionCheck } from './ArchbaseSecurityHooks';
|
|
23
|
+
export { ArchbaseProtectedComponent, ArchbaseSecureActionButton, ArchbaseSecureFormField, withArchbaseSecurity } from './ArchbaseSecurityComponents';
|
|
24
|
+
export type { ArchbaseSecurityContextType, ArchbaseViewSecurityContextType, ArchbaseSecurityProviderProps, ArchbaseViewSecurityProviderProps } from './ArchbaseSecurityContext';
|
|
25
|
+
export type { ArchbaseProtectedComponentProps, ArchbaseSecureActionButtonProps, ArchbaseSecureFormFieldProps } from './ArchbaseSecurityComponents';
|
|
26
|
+
export type { UseArchbaseSecureFormReturn } from './ArchbaseSecurityHooks';
|
|
27
|
+
export type * from './types/ArchbaseSecurityTypes';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { IArchbaseAuthContext, IArchbaseAuthProvider } from './Types';
|
|
3
|
+
export declare const ArchbaseAuthContext: React.Context<IArchbaseAuthContext>;
|
|
4
|
+
export declare const ArchbaseAuthProvider: ({ authConfig, children }: IArchbaseAuthProvider) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
interface TTokenRqBase {
|
|
3
|
+
grant_type: string;
|
|
4
|
+
scope?: string;
|
|
5
|
+
client_id: string;
|
|
6
|
+
redirect_uri: string;
|
|
7
|
+
}
|
|
8
|
+
export interface TTokenRequestWithCodeAndVerifier extends TTokenRqBase {
|
|
9
|
+
code: string;
|
|
10
|
+
code_verifier: string;
|
|
11
|
+
}
|
|
12
|
+
export interface TTokenRequestForRefresh extends TTokenRqBase {
|
|
13
|
+
refresh_token: string;
|
|
14
|
+
}
|
|
15
|
+
export type TTokenRequest = TTokenRequestWithCodeAndVerifier | TTokenRequestForRefresh;
|
|
16
|
+
export type TTokenData = {
|
|
17
|
+
[x: string]: any;
|
|
18
|
+
};
|
|
19
|
+
export type TTokenResponse = {
|
|
20
|
+
access_token: string;
|
|
21
|
+
scope: string;
|
|
22
|
+
token_type: string;
|
|
23
|
+
expires_in?: number;
|
|
24
|
+
refresh_token?: string;
|
|
25
|
+
refresh_token_expires_in?: number;
|
|
26
|
+
refresh_expires_in?: number;
|
|
27
|
+
id_token?: string;
|
|
28
|
+
};
|
|
29
|
+
export interface IArchbaseAuthProvider {
|
|
30
|
+
authConfig: TArchbaseAuthConfig;
|
|
31
|
+
children: ReactNode;
|
|
32
|
+
}
|
|
33
|
+
export interface IArchbaseAuthContext {
|
|
34
|
+
token: string;
|
|
35
|
+
logOut: (state?: string, logoutHint?: string) => void;
|
|
36
|
+
login: (state?: string) => void;
|
|
37
|
+
error: string | null;
|
|
38
|
+
tokenData?: TTokenData;
|
|
39
|
+
idToken?: string;
|
|
40
|
+
idTokenData?: TTokenData;
|
|
41
|
+
loginInProgress: boolean;
|
|
42
|
+
}
|
|
43
|
+
export type TArchbaseAuthConfig = {
|
|
44
|
+
clientId: string;
|
|
45
|
+
authorizationEndpoint: string;
|
|
46
|
+
tokenEndpoint: string;
|
|
47
|
+
redirectUri: string;
|
|
48
|
+
scope?: string;
|
|
49
|
+
state?: string;
|
|
50
|
+
logoutEndpoint?: string;
|
|
51
|
+
logoutRedirect?: string;
|
|
52
|
+
preLogin?: () => void;
|
|
53
|
+
postLogin?: () => void;
|
|
54
|
+
onRefreshTokenExpire?: (event: TArchbaseRefreshTokenExpiredEvent) => void;
|
|
55
|
+
decodeToken?: boolean;
|
|
56
|
+
autoLogin?: boolean;
|
|
57
|
+
clearURL?: boolean;
|
|
58
|
+
extraAuthParams?: {
|
|
59
|
+
[key: string]: string | boolean | number;
|
|
60
|
+
};
|
|
61
|
+
extraAuthParameters?: {
|
|
62
|
+
[key: string]: string | boolean | number;
|
|
63
|
+
};
|
|
64
|
+
extraTokenParameters?: {
|
|
65
|
+
[key: string]: string | boolean | number;
|
|
66
|
+
};
|
|
67
|
+
extraLogoutParameters?: {
|
|
68
|
+
[key: string]: string | boolean | number;
|
|
69
|
+
};
|
|
70
|
+
tokenExpiresIn?: number;
|
|
71
|
+
refreshTokenExpiresIn?: number;
|
|
72
|
+
storage?: 'session' | 'local';
|
|
73
|
+
};
|
|
74
|
+
export type TArchbaseRefreshTokenExpiredEvent = {
|
|
75
|
+
login: () => void;
|
|
76
|
+
};
|
|
77
|
+
export type TInternalConfig = {
|
|
78
|
+
clientId: string;
|
|
79
|
+
authorizationEndpoint: string;
|
|
80
|
+
tokenEndpoint: string;
|
|
81
|
+
redirectUri: string;
|
|
82
|
+
scope?: string;
|
|
83
|
+
state?: string;
|
|
84
|
+
logoutEndpoint?: string;
|
|
85
|
+
logoutRedirect?: string;
|
|
86
|
+
preLogin?: () => void;
|
|
87
|
+
postLogin?: () => void;
|
|
88
|
+
onRefreshTokenExpire?: (event: TArchbaseRefreshTokenExpiredEvent) => void;
|
|
89
|
+
decodeToken: boolean;
|
|
90
|
+
autoLogin: boolean;
|
|
91
|
+
clearURL: boolean;
|
|
92
|
+
extraAuthParams?: {
|
|
93
|
+
[key: string]: string | boolean | number;
|
|
94
|
+
};
|
|
95
|
+
extraAuthParameters?: {
|
|
96
|
+
[key: string]: string | boolean | number;
|
|
97
|
+
};
|
|
98
|
+
extraTokenParameters?: {
|
|
99
|
+
[key: string]: string | boolean | number;
|
|
100
|
+
};
|
|
101
|
+
extraLogoutParameters?: {
|
|
102
|
+
[key: string]: string | boolean | number;
|
|
103
|
+
};
|
|
104
|
+
tokenExpiresIn?: number;
|
|
105
|
+
refreshTokenExpiresIn?: number;
|
|
106
|
+
storage: 'session' | 'local';
|
|
107
|
+
};
|
|
108
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TInternalConfig, TTokenResponse } from './Types';
|
|
2
|
+
export declare function redirectToLogin(config: TInternalConfig, customState?: string): Promise<void>;
|
|
3
|
+
export declare const fetchTokens: (config: TInternalConfig) => Promise<TTokenResponse>;
|
|
4
|
+
export declare const fetchWithRefreshToken: (props: {
|
|
5
|
+
config: TInternalConfig;
|
|
6
|
+
refreshToken: string;
|
|
7
|
+
}) => Promise<TTokenResponse>;
|
|
8
|
+
export declare function redirectToLogout(config: TInternalConfig, token: string, refresh_token?: string, idToken?: string, state?: string, logoutHint?: string): void;
|
|
9
|
+
export declare function validateState(urlParams: URLSearchParams): void;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { ArchbaseAuthProvider, ArchbaseAuthContext } from './AuthContext';
|
|
2
|
+
export type { TArchbaseAuthConfig, IArchbaseAuthProvider, IArchbaseAuthContext, TArchbaseRefreshTokenExpiredEvent, TTokenRequestWithCodeAndVerifier, TTokenRequestForRefresh, TTokenRequest, TTokenData, TTokenResponse, TInternalConfig, } from './Types';
|
|
3
|
+
export { epochAtSecondsFromNow, epochTimeIsPast, getRefreshExpiresIn } from './timeUtils';
|
|
4
|
+
export { getRandomInteger, generateRandomString, generateCodeChallenge } from './pkceUtils';
|
|
5
|
+
export { postWithXForm } from './httpUtils';
|
|
6
|
+
export * as useBrowserStorage from './hooks';
|
|
7
|
+
export { FetchError } from './errors';
|
|
8
|
+
export { decodeJWT } from './decodeJWT';
|
|
9
|
+
export { redirectToLogin, fetchTokens, fetchWithRefreshToken, redirectToLogout, validateState } from './authentication';
|
|
10
|
+
export { createInternalConfig, validateConfig } from './authConfig';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function getRandomInteger(range: number): number;
|
|
2
|
+
export declare function generateRandomString(length: number): string;
|
|
3
|
+
/**
|
|
4
|
+
* PKCE Code Challenge = base64url(hash(codeVerifier))
|
|
5
|
+
*/
|
|
6
|
+
export declare function generateCodeChallenge(codeVerifier: string): Promise<string>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TTokenResponse } from './Types';
|
|
2
|
+
export declare const FALLBACK_EXPIRE_TIME = 600;
|
|
3
|
+
export declare const epochAtSecondsFromNow: (secondsFromNow: number) => number;
|
|
4
|
+
/**
|
|
5
|
+
* Verifique se o token de acesso expirou.
|
|
6
|
+
* Retornará True se o token expirou OU falta menos de 30 segundos para expirar.
|
|
7
|
+
*/
|
|
8
|
+
export declare function epochTimeIsPast(timestamp: number): boolean;
|
|
9
|
+
export declare function getRefreshExpiresIn(tokenExpiresIn: number, response: TTokenResponse): number;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { ArchbaseSecurityManager } from '../ArchbaseSecurityManager';
|
|
3
|
+
import { UserDto } from '../SecurityDomain';
|
|
4
|
+
export interface ArchbaseSecurityError {
|
|
5
|
+
code: string;
|
|
6
|
+
message: string;
|
|
7
|
+
details?: any;
|
|
8
|
+
}
|
|
9
|
+
export type ArchbasePermissionAction = string;
|
|
10
|
+
export type ArchbasePermissionList = ArchbasePermissionAction[];
|
|
11
|
+
export interface ArchbaseGlobalSecurityState {
|
|
12
|
+
user: UserDto | null;
|
|
13
|
+
isAuthenticated: boolean;
|
|
14
|
+
isLoading: boolean;
|
|
15
|
+
error: ArchbaseSecurityError | null;
|
|
16
|
+
}
|
|
17
|
+
export interface ArchbaseViewSecurityConfig {
|
|
18
|
+
resourceName: string;
|
|
19
|
+
resourceDescription: string;
|
|
20
|
+
requiredPermissions?: ArchbasePermissionList;
|
|
21
|
+
autoRegisterActions?: boolean;
|
|
22
|
+
strictMode?: boolean;
|
|
23
|
+
}
|
|
24
|
+
export interface ArchbaseProtectionConfig {
|
|
25
|
+
actionName?: ArchbasePermissionAction;
|
|
26
|
+
requiredPermissions?: ArchbasePermissionList;
|
|
27
|
+
requireAll?: boolean;
|
|
28
|
+
fallback?: ReactNode;
|
|
29
|
+
autoRegister?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export type ArchbaseSecurityCallback = (manager: ArchbaseSecurityManager) => void;
|
|
32
|
+
export type ArchbaseErrorCallback = (error: string) => void;
|
|
33
|
+
export interface ArchbasePermissionCheckResult {
|
|
34
|
+
hasAccess: boolean;
|
|
35
|
+
missingPermissions?: ArchbasePermissionList;
|
|
36
|
+
reason?: string;
|
|
37
|
+
}
|
|
38
|
+
export declare enum ArchbaseFallbackType {
|
|
39
|
+
HIDDEN = "hidden",
|
|
40
|
+
DISABLED = "disabled",
|
|
41
|
+
MESSAGE = "message",
|
|
42
|
+
CUSTOM = "custom"
|
|
43
|
+
}
|
|
44
|
+
export interface ArchbaseAdvancedSecurityConfig extends ArchbaseViewSecurityConfig {
|
|
45
|
+
fallbackType?: ArchbaseFallbackType;
|
|
46
|
+
customFallback?: ReactNode;
|
|
47
|
+
onAccessDenied?: (missingPermissions: ArchbasePermissionList) => void;
|
|
48
|
+
onError?: ArchbaseErrorCallback;
|
|
49
|
+
debugMode?: boolean;
|
|
50
|
+
}
|