@abpjs/identity 0.7.6
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 +165 -0
- package/README.md +533 -0
- package/dist/index.d.mts +463 -0
- package/dist/index.d.ts +463 -0
- package/dist/index.js +1161 -0
- package/dist/index.mjs +1146 -0
- package/package.json +85 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 29 June 2007
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
|
6
|
+
of this license document, but changing it is not allowed.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
|
11
|
+
License, supplemented by the additional permissions listed below.
|
|
12
|
+
|
|
13
|
+
0. Additional Definitions.
|
|
14
|
+
|
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
|
17
|
+
General Public License.
|
|
18
|
+
|
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
|
20
|
+
other than an Application or a Combined Work as defined below.
|
|
21
|
+
|
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
|
25
|
+
of using an interface provided by the Library.
|
|
26
|
+
|
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
|
28
|
+
Application with the Library. The particular version of the Library
|
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
|
30
|
+
Version".
|
|
31
|
+
|
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
|
35
|
+
based on the Application, and not on the Linked Version.
|
|
36
|
+
|
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
|
38
|
+
object code and/or source code for the Application, including any data
|
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
|
41
|
+
|
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
|
43
|
+
|
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
|
46
|
+
|
|
47
|
+
2. Conveying Modified Versions.
|
|
48
|
+
|
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
|
51
|
+
that uses the facility (other than as an argument passed when the
|
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
|
53
|
+
version:
|
|
54
|
+
|
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
|
56
|
+
ensure that, in the event an Application does not supply the
|
|
57
|
+
function or data, the facility still operates, and performs
|
|
58
|
+
whatever part of its purpose remains meaningful, or
|
|
59
|
+
|
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
|
61
|
+
this License applicable to that copy.
|
|
62
|
+
|
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
|
64
|
+
|
|
65
|
+
The object code form of an Application may incorporate material from
|
|
66
|
+
a header file that is part of the Library. You may convey such object
|
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
|
68
|
+
material is not limited to numerical parameters, data structure
|
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
|
71
|
+
|
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
|
73
|
+
Library is used in it and that the Library and its use are
|
|
74
|
+
covered by this License.
|
|
75
|
+
|
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
|
77
|
+
document.
|
|
78
|
+
|
|
79
|
+
4. Combined Works.
|
|
80
|
+
|
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
|
82
|
+
taken together, effectively do not restrict modification of the
|
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
|
85
|
+
the following:
|
|
86
|
+
|
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
|
88
|
+
the Library is used in it and that the Library and its use are
|
|
89
|
+
covered by this License.
|
|
90
|
+
|
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
|
92
|
+
document.
|
|
93
|
+
|
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
|
95
|
+
execution, include the copyright notice for the Library among
|
|
96
|
+
these notices, as well as a reference directing the user to the
|
|
97
|
+
copies of the GNU GPL and this license document.
|
|
98
|
+
|
|
99
|
+
d) Do one of the following:
|
|
100
|
+
|
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
|
102
|
+
License, and the Corresponding Application Code in a form
|
|
103
|
+
suitable for, and under terms that permit, the user to
|
|
104
|
+
recombine or relink the Application with a modified version of
|
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
|
107
|
+
Corresponding Source.
|
|
108
|
+
|
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
|
111
|
+
a copy of the Library already present on the user's computer
|
|
112
|
+
system, and (b) will operate properly with a modified version of
|
|
113
|
+
the Library that is interface-compatible with the Linked
|
|
114
|
+
Version.
|
|
115
|
+
|
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
|
117
|
+
be required to provide such information under section 6 of the
|
|
118
|
+
GNU GPL, and only to the extent that such information is
|
|
119
|
+
necessary to install and execute a modified version of the
|
|
120
|
+
Combined Work produced by recombining or relinking the
|
|
121
|
+
Application with a modified version of the Linked Version. (If
|
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
|
126
|
+
for conveying Corresponding Source.)
|
|
127
|
+
|
|
128
|
+
5. Combined Libraries.
|
|
129
|
+
|
|
130
|
+
You may place library facilities that are a work based on the
|
|
131
|
+
Library side by side in a single library together with other library
|
|
132
|
+
facilities that are not Applications and are not covered by this
|
|
133
|
+
License, and convey such a combined library under terms of your
|
|
134
|
+
choice, if you do both of the following:
|
|
135
|
+
|
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
|
137
|
+
on the Library, uncombined with any other library facilities,
|
|
138
|
+
conveyed under the terms of this License.
|
|
139
|
+
|
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
|
141
|
+
is a work based on the Library, and explaining where to find the
|
|
142
|
+
accompanying uncombined form of the same work.
|
|
143
|
+
|
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
|
145
|
+
|
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
|
148
|
+
versions will be similar in spirit to the present version, but may
|
|
149
|
+
differ in detail to address new problems or concerns.
|
|
150
|
+
|
|
151
|
+
Each version is given a distinguishing version number. If the
|
|
152
|
+
Library as you received it specifies that a certain numbered version
|
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
|
154
|
+
applies to it, you have the option of following the terms and
|
|
155
|
+
conditions either of that published version or of any later version
|
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
|
160
|
+
|
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
|
164
|
+
permanent authorization for you to choose that version for the
|
|
165
|
+
Library.
|
package/README.md
ADDED
|
@@ -0,0 +1,533 @@
|
|
|
1
|
+
# @abpjs/identity
|
|
2
|
+
|
|
3
|
+
> User and role management UI components for ABP Framework in React
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@abpjs/identity)
|
|
6
|
+
[](https://www.gnu.org/licenses/lgpl-3.0)
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
`@abpjs/identity` provides a complete identity management interface for ABP-based React applications. It includes comprehensive user and role management with CRUD operations, role assignment, permission management integration, and pagination support.
|
|
11
|
+
|
|
12
|
+
This package is a React translation of the original `@abp/ng.identity` Angular package, bringing full identity management capabilities to React applications.
|
|
13
|
+
|
|
14
|
+
## Features
|
|
15
|
+
|
|
16
|
+
- **User Management** - Create, read, update, and delete users
|
|
17
|
+
- **Role Management** - Create, read, update, and delete roles
|
|
18
|
+
- **Role Assignment** - Assign roles to users with checkbox interface
|
|
19
|
+
- **Permission Integration** - Seamlessly integrates with permission management
|
|
20
|
+
- **Pagination** - Built-in pagination for user lists
|
|
21
|
+
- **Search & Filter** - Filter users and roles by name
|
|
22
|
+
- **Localization** - Full i18n support using ABP localization
|
|
23
|
+
- **Chakra UI** - Beautiful, accessible components
|
|
24
|
+
- **TypeScript** - Full type safety with comprehensive definitions
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
# Using npm
|
|
30
|
+
npm install @abpjs/identity
|
|
31
|
+
|
|
32
|
+
# Using yarn
|
|
33
|
+
yarn add @abpjs/identity
|
|
34
|
+
|
|
35
|
+
# Using pnpm
|
|
36
|
+
pnpm add @abpjs/identity
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Required Dependencies
|
|
40
|
+
|
|
41
|
+
This package requires the following peer dependencies:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
npm install @abpjs/core @abpjs/theme-shared @abpjs/permission-management @chakra-ui/react @emotion/react @emotion/styled framer-motion
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Quick Start
|
|
48
|
+
|
|
49
|
+
### Using Pre-built Components
|
|
50
|
+
|
|
51
|
+
The easiest way to add identity management to your app:
|
|
52
|
+
|
|
53
|
+
```tsx
|
|
54
|
+
import { RolesComponent, UsersComponent } from '@abpjs/identity';
|
|
55
|
+
import { Tabs, TabList, TabPanels, Tab, TabPanel } from '@chakra-ui/react';
|
|
56
|
+
|
|
57
|
+
function IdentityManagement() {
|
|
58
|
+
return (
|
|
59
|
+
<Tabs>
|
|
60
|
+
<TabList>
|
|
61
|
+
<Tab>Users</Tab>
|
|
62
|
+
<Tab>Roles</Tab>
|
|
63
|
+
</TabList>
|
|
64
|
+
|
|
65
|
+
<TabPanels>
|
|
66
|
+
<TabPanel>
|
|
67
|
+
<UsersComponent
|
|
68
|
+
onUserCreated={(user) => console.log('User created:', user)}
|
|
69
|
+
onUserDeleted={(id) => console.log('User deleted:', id)}
|
|
70
|
+
/>
|
|
71
|
+
</TabPanel>
|
|
72
|
+
<TabPanel>
|
|
73
|
+
<RolesComponent
|
|
74
|
+
onRoleCreated={(role) => console.log('Role created:', role)}
|
|
75
|
+
onRoleDeleted={(id) => console.log('Role deleted:', id)}
|
|
76
|
+
/>
|
|
77
|
+
</TabPanel>
|
|
78
|
+
</TabPanels>
|
|
79
|
+
</Tabs>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Using Hooks for Custom UI
|
|
85
|
+
|
|
86
|
+
Build your own identity UI using the provided hooks:
|
|
87
|
+
|
|
88
|
+
```tsx
|
|
89
|
+
import { useUsers, useRoles, Identity } from '@abpjs/identity';
|
|
90
|
+
import { useEffect } from 'react';
|
|
91
|
+
|
|
92
|
+
function CustomUsersPage() {
|
|
93
|
+
const {
|
|
94
|
+
users,
|
|
95
|
+
totalCount,
|
|
96
|
+
isLoading,
|
|
97
|
+
fetchUsers,
|
|
98
|
+
createUser,
|
|
99
|
+
deleteUser,
|
|
100
|
+
} = useUsers();
|
|
101
|
+
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
fetchUsers();
|
|
104
|
+
}, [fetchUsers]);
|
|
105
|
+
|
|
106
|
+
const handleCreateUser = async (data: Identity.UserSaveRequest) => {
|
|
107
|
+
const result = await createUser(data);
|
|
108
|
+
if (result.success) {
|
|
109
|
+
console.log('User created successfully!');
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
return (
|
|
114
|
+
<div>
|
|
115
|
+
<h1>Users ({totalCount})</h1>
|
|
116
|
+
{users.map(user => (
|
|
117
|
+
<div key={user.id}>
|
|
118
|
+
<span>{user.userName}</span>
|
|
119
|
+
<span>{user.email}</span>
|
|
120
|
+
<button onClick={() => deleteUser(user.id)}>Delete</button>
|
|
121
|
+
</div>
|
|
122
|
+
))}
|
|
123
|
+
</div>
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Components
|
|
129
|
+
|
|
130
|
+
### UsersComponent
|
|
131
|
+
|
|
132
|
+
Complete user management component with table, search, pagination, and modals.
|
|
133
|
+
|
|
134
|
+
```tsx
|
|
135
|
+
import { UsersComponent } from '@abpjs/identity';
|
|
136
|
+
|
|
137
|
+
<UsersComponent
|
|
138
|
+
onUserCreated={(user) => console.log('Created:', user)}
|
|
139
|
+
onUserUpdated={(user) => console.log('Updated:', user)}
|
|
140
|
+
onUserDeleted={(id) => console.log('Deleted:', id)}
|
|
141
|
+
/>
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
**Props:**
|
|
145
|
+
|
|
146
|
+
| Prop | Type | Description |
|
|
147
|
+
|------|------|-------------|
|
|
148
|
+
| `onUserCreated` | `(user: UserItem) => void` | Callback when user is created |
|
|
149
|
+
| `onUserUpdated` | `(user: UserItem) => void` | Callback when user is updated |
|
|
150
|
+
| `onUserDeleted` | `(id: string) => void` | Callback when user is deleted |
|
|
151
|
+
|
|
152
|
+
**Features:**
|
|
153
|
+
- User table with actions menu
|
|
154
|
+
- Search/filter by username
|
|
155
|
+
- Pagination controls
|
|
156
|
+
- Create/Edit modal with tabs for user info and role assignment
|
|
157
|
+
- Permission management integration
|
|
158
|
+
- Delete confirmation dialog
|
|
159
|
+
|
|
160
|
+
### RolesComponent
|
|
161
|
+
|
|
162
|
+
Complete role management component with table, search, and modals.
|
|
163
|
+
|
|
164
|
+
```tsx
|
|
165
|
+
import { RolesComponent } from '@abpjs/identity';
|
|
166
|
+
|
|
167
|
+
<RolesComponent
|
|
168
|
+
onRoleCreated={(role) => console.log('Created:', role)}
|
|
169
|
+
onRoleUpdated={(role) => console.log('Updated:', role)}
|
|
170
|
+
onRoleDeleted={(id) => console.log('Deleted:', id)}
|
|
171
|
+
/>
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
**Props:**
|
|
175
|
+
|
|
176
|
+
| Prop | Type | Description |
|
|
177
|
+
|------|------|-------------|
|
|
178
|
+
| `onRoleCreated` | `(role: RoleItem) => void` | Callback when role is created |
|
|
179
|
+
| `onRoleUpdated` | `(role: RoleItem) => void` | Callback when role is updated |
|
|
180
|
+
| `onRoleDeleted` | `(id: string) => void` | Callback when role is deleted |
|
|
181
|
+
|
|
182
|
+
**Features:**
|
|
183
|
+
- Role table with actions menu
|
|
184
|
+
- Search/filter by role name
|
|
185
|
+
- Create/Edit modal with isDefault and isPublic options
|
|
186
|
+
- Permission management integration
|
|
187
|
+
- Static role protection (cannot delete static roles)
|
|
188
|
+
- Delete confirmation dialog
|
|
189
|
+
|
|
190
|
+
## Hooks
|
|
191
|
+
|
|
192
|
+
### useUsers
|
|
193
|
+
|
|
194
|
+
Hook for managing users with full CRUD and pagination support.
|
|
195
|
+
|
|
196
|
+
```tsx
|
|
197
|
+
import { useUsers } from '@abpjs/identity';
|
|
198
|
+
|
|
199
|
+
function MyUsersPage() {
|
|
200
|
+
const {
|
|
201
|
+
users, // Array of users
|
|
202
|
+
totalCount, // Total user count
|
|
203
|
+
selectedUser, // Currently selected user
|
|
204
|
+
selectedUserRoles, // Roles of selected user
|
|
205
|
+
isLoading, // Loading state
|
|
206
|
+
error, // Error message
|
|
207
|
+
pageQuery, // Current pagination params
|
|
208
|
+
fetchUsers, // Fetch users with optional params
|
|
209
|
+
getUserById, // Get single user
|
|
210
|
+
getUserRoles, // Get user's roles
|
|
211
|
+
createUser, // Create new user
|
|
212
|
+
updateUser, // Update existing user
|
|
213
|
+
deleteUser, // Delete user
|
|
214
|
+
setSelectedUser, // Set selected user
|
|
215
|
+
setPageQuery, // Update pagination params
|
|
216
|
+
reset, // Reset all state
|
|
217
|
+
} = useUsers();
|
|
218
|
+
|
|
219
|
+
// Fetch users on mount
|
|
220
|
+
useEffect(() => {
|
|
221
|
+
fetchUsers();
|
|
222
|
+
}, [fetchUsers]);
|
|
223
|
+
|
|
224
|
+
// Pagination example
|
|
225
|
+
const handlePageChange = (page: number) => {
|
|
226
|
+
const newQuery = {
|
|
227
|
+
...pageQuery,
|
|
228
|
+
skipCount: page * pageQuery.maxResultCount,
|
|
229
|
+
};
|
|
230
|
+
setPageQuery(newQuery);
|
|
231
|
+
fetchUsers(newQuery);
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
// Create user example
|
|
235
|
+
const handleCreate = async () => {
|
|
236
|
+
const result = await createUser({
|
|
237
|
+
userName: 'newuser',
|
|
238
|
+
email: 'user@example.com',
|
|
239
|
+
password: 'SecurePassword123!',
|
|
240
|
+
name: 'John',
|
|
241
|
+
surname: 'Doe',
|
|
242
|
+
phoneNumber: '',
|
|
243
|
+
lockoutEnabled: true,
|
|
244
|
+
twoFactorEnabled: false,
|
|
245
|
+
roleNames: ['admin'],
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
if (result.success) {
|
|
249
|
+
console.log('User created!');
|
|
250
|
+
} else {
|
|
251
|
+
console.error(result.error);
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### useRoles
|
|
258
|
+
|
|
259
|
+
Hook for managing roles with full CRUD support.
|
|
260
|
+
|
|
261
|
+
```tsx
|
|
262
|
+
import { useRoles } from '@abpjs/identity';
|
|
263
|
+
|
|
264
|
+
function MyRolesPage() {
|
|
265
|
+
const {
|
|
266
|
+
roles, // Array of roles
|
|
267
|
+
totalCount, // Total role count
|
|
268
|
+
selectedRole, // Currently selected role
|
|
269
|
+
isLoading, // Loading state
|
|
270
|
+
error, // Error message
|
|
271
|
+
fetchRoles, // Fetch all roles
|
|
272
|
+
getRoleById, // Get single role
|
|
273
|
+
createRole, // Create new role
|
|
274
|
+
updateRole, // Update existing role
|
|
275
|
+
deleteRole, // Delete role
|
|
276
|
+
setSelectedRole, // Set selected role
|
|
277
|
+
reset, // Reset all state
|
|
278
|
+
} = useRoles();
|
|
279
|
+
|
|
280
|
+
// Fetch roles on mount
|
|
281
|
+
useEffect(() => {
|
|
282
|
+
fetchRoles();
|
|
283
|
+
}, [fetchRoles]);
|
|
284
|
+
|
|
285
|
+
// Create role example
|
|
286
|
+
const handleCreate = async () => {
|
|
287
|
+
const result = await createRole({
|
|
288
|
+
name: 'Manager',
|
|
289
|
+
isDefault: false,
|
|
290
|
+
isPublic: true,
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
if (result.success) {
|
|
294
|
+
console.log('Role created!');
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
### useIdentity
|
|
301
|
+
|
|
302
|
+
Combined hook for managing both users and roles.
|
|
303
|
+
|
|
304
|
+
```tsx
|
|
305
|
+
import { useIdentity } from '@abpjs/identity';
|
|
306
|
+
|
|
307
|
+
function IdentityDashboard() {
|
|
308
|
+
const { roles, users, fetchRoles, fetchUsers } = useIdentity();
|
|
309
|
+
|
|
310
|
+
useEffect(() => {
|
|
311
|
+
fetchRoles();
|
|
312
|
+
fetchUsers();
|
|
313
|
+
}, []);
|
|
314
|
+
|
|
315
|
+
return (
|
|
316
|
+
<div>
|
|
317
|
+
<h2>Users: {users.length}</h2>
|
|
318
|
+
<h2>Roles: {roles.length}</h2>
|
|
319
|
+
</div>
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
## Services
|
|
325
|
+
|
|
326
|
+
### IdentityService
|
|
327
|
+
|
|
328
|
+
Service class for direct API interaction.
|
|
329
|
+
|
|
330
|
+
```tsx
|
|
331
|
+
import { IdentityService } from '@abpjs/identity';
|
|
332
|
+
import { useRestService } from '@abpjs/core';
|
|
333
|
+
|
|
334
|
+
function MyComponent() {
|
|
335
|
+
const restService = useRestService();
|
|
336
|
+
const identityService = new IdentityService(restService);
|
|
337
|
+
|
|
338
|
+
// Role operations
|
|
339
|
+
const roles = await identityService.getRoles();
|
|
340
|
+
const role = await identityService.getRoleById(roleId);
|
|
341
|
+
await identityService.createRole({ name: 'Editor', isDefault: false, isPublic: true });
|
|
342
|
+
await identityService.updateRole(roleId, { name: 'Senior Editor', isDefault: false, isPublic: true });
|
|
343
|
+
await identityService.deleteRole(roleId);
|
|
344
|
+
|
|
345
|
+
// User operations
|
|
346
|
+
const users = await identityService.getUsers({ maxResultCount: 10, skipCount: 0 });
|
|
347
|
+
const user = await identityService.getUserById(userId);
|
|
348
|
+
const userRoles = await identityService.getUserRoles(userId);
|
|
349
|
+
await identityService.createUser({ userName: 'john', email: 'john@example.com', password: 'Pass123!', ... });
|
|
350
|
+
await identityService.updateUser(userId, { ... });
|
|
351
|
+
await identityService.deleteUser(userId);
|
|
352
|
+
}
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
## Data Models
|
|
356
|
+
|
|
357
|
+
### Identity Namespace
|
|
358
|
+
|
|
359
|
+
All identity types are exported under the `Identity` namespace:
|
|
360
|
+
|
|
361
|
+
```typescript
|
|
362
|
+
import { Identity } from '@abpjs/identity';
|
|
363
|
+
|
|
364
|
+
// State shape
|
|
365
|
+
interface Identity.State {
|
|
366
|
+
roles: RoleResponse;
|
|
367
|
+
users: UserResponse;
|
|
368
|
+
selectedRole: RoleItem;
|
|
369
|
+
selectedUser: UserItem;
|
|
370
|
+
selectedUserRoles: RoleItem[];
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// Role types
|
|
374
|
+
interface Identity.RoleItem {
|
|
375
|
+
id: string;
|
|
376
|
+
name: string;
|
|
377
|
+
isDefault: boolean;
|
|
378
|
+
isPublic: boolean;
|
|
379
|
+
isStatic: boolean;
|
|
380
|
+
concurrencyStamp: string;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
interface Identity.RoleSaveRequest {
|
|
384
|
+
name: string;
|
|
385
|
+
isDefault: boolean;
|
|
386
|
+
isPublic: boolean;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// User types
|
|
390
|
+
interface Identity.UserItem {
|
|
391
|
+
id: string;
|
|
392
|
+
tenantId: string;
|
|
393
|
+
userName: string;
|
|
394
|
+
name: string;
|
|
395
|
+
surname: string;
|
|
396
|
+
email: string;
|
|
397
|
+
emailConfirmed: boolean;
|
|
398
|
+
phoneNumber: string;
|
|
399
|
+
phoneNumberConfirmed: boolean;
|
|
400
|
+
twoFactorEnabled: boolean;
|
|
401
|
+
lockoutEnabled: boolean;
|
|
402
|
+
isLockedOut: boolean;
|
|
403
|
+
concurrencyStamp: string;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
interface Identity.UserSaveRequest {
|
|
407
|
+
userName: string;
|
|
408
|
+
name: string;
|
|
409
|
+
surname: string;
|
|
410
|
+
email: string;
|
|
411
|
+
phoneNumber: string;
|
|
412
|
+
password: string;
|
|
413
|
+
lockoutEnabled: boolean;
|
|
414
|
+
twoFactorEnabled: boolean;
|
|
415
|
+
roleNames: string[];
|
|
416
|
+
}
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
## Integration Example
|
|
420
|
+
|
|
421
|
+
Complete identity management page:
|
|
422
|
+
|
|
423
|
+
```tsx
|
|
424
|
+
import { useState } from 'react';
|
|
425
|
+
import { usePermission } from '@abpjs/core';
|
|
426
|
+
import { RolesComponent, UsersComponent } from '@abpjs/identity';
|
|
427
|
+
import {
|
|
428
|
+
Box,
|
|
429
|
+
Tabs,
|
|
430
|
+
TabList,
|
|
431
|
+
TabPanels,
|
|
432
|
+
Tab,
|
|
433
|
+
TabPanel,
|
|
434
|
+
Heading,
|
|
435
|
+
useToast,
|
|
436
|
+
} from '@chakra-ui/react';
|
|
437
|
+
|
|
438
|
+
function IdentityManagementPage() {
|
|
439
|
+
const toast = useToast();
|
|
440
|
+
const { hasPermission } = usePermission();
|
|
441
|
+
|
|
442
|
+
const canViewUsers = hasPermission('AbpIdentity.Users');
|
|
443
|
+
const canViewRoles = hasPermission('AbpIdentity.Roles');
|
|
444
|
+
|
|
445
|
+
const handleUserCreated = (user) => {
|
|
446
|
+
toast({ title: `User ${user.userName} created`, status: 'success' });
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
const handleUserDeleted = () => {
|
|
450
|
+
toast({ title: 'User deleted', status: 'success' });
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
const handleRoleCreated = (role) => {
|
|
454
|
+
toast({ title: `Role ${role.name} created`, status: 'success' });
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
const handleRoleDeleted = () => {
|
|
458
|
+
toast({ title: 'Role deleted', status: 'success' });
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
return (
|
|
462
|
+
<Box p={4}>
|
|
463
|
+
<Heading mb={4}>Identity Management</Heading>
|
|
464
|
+
|
|
465
|
+
<Tabs>
|
|
466
|
+
<TabList>
|
|
467
|
+
{canViewUsers && <Tab>Users</Tab>}
|
|
468
|
+
{canViewRoles && <Tab>Roles</Tab>}
|
|
469
|
+
</TabList>
|
|
470
|
+
|
|
471
|
+
<TabPanels>
|
|
472
|
+
{canViewUsers && (
|
|
473
|
+
<TabPanel>
|
|
474
|
+
<UsersComponent
|
|
475
|
+
onUserCreated={handleUserCreated}
|
|
476
|
+
onUserDeleted={handleUserDeleted}
|
|
477
|
+
/>
|
|
478
|
+
</TabPanel>
|
|
479
|
+
)}
|
|
480
|
+
{canViewRoles && (
|
|
481
|
+
<TabPanel>
|
|
482
|
+
<RolesComponent
|
|
483
|
+
onRoleCreated={handleRoleCreated}
|
|
484
|
+
onRoleDeleted={handleRoleDeleted}
|
|
485
|
+
/>
|
|
486
|
+
</TabPanel>
|
|
487
|
+
)}
|
|
488
|
+
</TabPanels>
|
|
489
|
+
</Tabs>
|
|
490
|
+
</Box>
|
|
491
|
+
);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
export default IdentityManagementPage;
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
## ABP Permissions
|
|
498
|
+
|
|
499
|
+
This package respects ABP's identity permissions:
|
|
500
|
+
|
|
501
|
+
| Permission | Description |
|
|
502
|
+
|------------|-------------|
|
|
503
|
+
| `AbpIdentity.Users` | View users |
|
|
504
|
+
| `AbpIdentity.Users.Create` | Create users |
|
|
505
|
+
| `AbpIdentity.Users.Update` | Update users |
|
|
506
|
+
| `AbpIdentity.Users.Delete` | Delete users |
|
|
507
|
+
| `AbpIdentity.Users.ManagePermissions` | Manage user permissions |
|
|
508
|
+
| `AbpIdentity.Roles` | View roles |
|
|
509
|
+
| `AbpIdentity.Roles.Create` | Create roles |
|
|
510
|
+
| `AbpIdentity.Roles.Update` | Update roles |
|
|
511
|
+
| `AbpIdentity.Roles.Delete` | Delete roles |
|
|
512
|
+
| `AbpIdentity.Roles.ManagePermissions` | Manage role permissions |
|
|
513
|
+
|
|
514
|
+
## Related Packages
|
|
515
|
+
|
|
516
|
+
- [@abpjs/core](https://www.npmjs.com/package/@abpjs/core) - Core infrastructure (required)
|
|
517
|
+
- [@abpjs/theme-shared](https://www.npmjs.com/package/@abpjs/theme-shared) - Shared UI components (required)
|
|
518
|
+
- [@abpjs/permission-management](https://www.npmjs.com/package/@abpjs/permission-management) - Permission management (required)
|
|
519
|
+
- [@abpjs/account](https://www.npmjs.com/package/@abpjs/account) - Account management
|
|
520
|
+
- [@abpjs/tenant-management](https://www.npmjs.com/package/@abpjs/tenant-management) - Tenant administration
|
|
521
|
+
- [@abpjs/theme-basic](https://www.npmjs.com/package/@abpjs/theme-basic) - Layout components
|
|
522
|
+
|
|
523
|
+
## Contributing
|
|
524
|
+
|
|
525
|
+
This package is part of the [ABP React](https://github.com/abpjs/abp-react) monorepo. Contributions are welcome!
|
|
526
|
+
|
|
527
|
+
## License
|
|
528
|
+
|
|
529
|
+
LGPL-3.0 - See [LICENSE](https://github.com/abpjs/abp-react/blob/main/LICENSE) for details.
|
|
530
|
+
|
|
531
|
+
---
|
|
532
|
+
|
|
533
|
+
**[View Full Documentation](https://docs.abpjs.io/docs/packages/identity/overview)** | **[Report Issues](https://github.com/abpjs/abp-react/issues)** | **[View Source](https://github.com/abpjs/abp-react/tree/main/packages/identity)**
|