@fraym/auth 0.1.0 → 0.2.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/README.md CHANGED
@@ -95,6 +95,68 @@ await managementClient.upsertRole("TENANT_ID", "ROLE_ID", [
95
95
  await managementClient.deleteRole("TENANT_ID", "ROLE_ID");
96
96
  ```
97
97
 
98
+ ## Create a user
99
+
100
+ When creating a user and not providing a `password`, the create function will return a `setInitialPasswordToken`. This string can be used to authorize the initial password change of a user. Use it within the graphql api to change the passwort of a user.
101
+
102
+ Required parameters:
103
+
104
+ ```typescript
105
+ const { id, setInitialPasswordToken } = await managementClient.createUser("TENANT_ID", "E-MAIL", [
106
+ "ROLE_ID",
107
+ ]);
108
+ ```
109
+
110
+ With all optional parameters:
111
+
112
+ ```typescript
113
+ const isActive = true;
114
+ const blockedUntil = new Date();
115
+ const {id, setInitialPasswordToken} = await managementClient.createUser("TENANT_ID", "E-MAIL", ["ROLE_ID"]. "LOGIN_NAME", "DISPLAY_NAME", "PASSWORD", isActive, blockedUntil);
116
+ ```
117
+
118
+ `LOGIN_NAME`: A name used for login instead of the email address.
119
+ `DISPLAY_NAME`: A name to display in the applications.
120
+ `PASSWORD`: Set the initial password of the user or leave empty if you want the user to set it.
121
+ `isActive`: Activate or deactivate a user.
122
+ `blockedUntil`: Block a user until a specific date.
123
+
124
+ ## Update a user
125
+
126
+ When updating a user and not providing a `password`, the password will stay the same. Otherwise it will be changed to the given password.
127
+
128
+ Required parameters:
129
+
130
+ ```typescript
131
+ await managementClient.updateUser("TENANT_ID", "USER_ID", "E-MAIL", ["ROLE_ID"]);
132
+ ```
133
+
134
+ With all optional parameters:
135
+
136
+ ```typescript
137
+ const isActive = true;
138
+ const blockedUntil = new Date();
139
+ await managementClient.createUser("TENANT_ID", "USER_ID", "E-MAIL", ["ROLE_ID"]. "LOGIN_NAME", "DISPLAY_NAME", "PASSWORD", isActive, blockedUntil);
140
+ ```
141
+
142
+ `LOGIN_NAME`: A name used for login instead of the email address.
143
+ `DISPLAY_NAME`: A name to display in the applications.
144
+ `PASSWORD`: Use this to reset the password of a user.
145
+ `isActive`: Activate or deactivate a user.
146
+ `blockedUntil`: Block a user until a specific date.
147
+
148
+ ## Delete a user
149
+
150
+ ```typescript
151
+ await managementClient.deleteUser("TENANT_ID", "USER_ID");
152
+ ```
153
+
154
+ ## Get all users
155
+
156
+ ```typescript
157
+ const users = await managementClient.getUsers("TENANT_ID");
158
+ ```
159
+
98
160
  ### Gracefully close the clients
99
161
 
100
162
  You won't lose any data if you don't. Use it for your peace of mind.
@@ -1,5 +1,7 @@
1
1
  import { ClientConfig } from "../config/config";
2
+ import { CreateUserResponse } from "./createUser";
2
3
  import { Role } from "./getRoles";
4
+ import { User } from "./getUsers";
3
5
  import { UpsertRoleScope } from "./upsertRole";
4
6
  export interface ManagementClient {
5
7
  createScope: (name: string, clientId?: string) => Promise<void>;
@@ -8,6 +10,10 @@ export interface ManagementClient {
8
10
  upsertRole: (tenantId: string, id: string, allowedScopes: UpsertRoleScope[]) => Promise<void>;
9
11
  deleteRole: (tenantId: string, id: string) => Promise<void>;
10
12
  getRoles: (tenantId: string) => Promise<Role[]>;
13
+ createUser: (tenantId: string, email: string, assignedRoleIds: string[], login?: string, displayName?: string, password?: string, active?: boolean, blockedUntil?: Date) => Promise<CreateUserResponse>;
14
+ updateUser: (tenantId: string, id: string, email: string, assignedRoleIds: string[], login?: string, displayName?: string, password?: string, active?: boolean, blockedUntil?: Date) => Promise<void>;
15
+ deleteUser: (tenantId: string, id: string) => Promise<void>;
16
+ getUsers: (tenantId: string) => Promise<User[]>;
11
17
  close: () => Promise<void>;
12
18
  }
13
19
  export declare const newManagementClient: (config?: ClientConfig) => Promise<ManagementClient>;
@@ -5,10 +5,14 @@ const auth_proto_1 = require("@fraym/auth-proto");
5
5
  const grpc_js_1 = require("@grpc/grpc-js");
6
6
  const config_1 = require("../config/config");
7
7
  const createScope_1 = require("./createScope");
8
+ const createUser_1 = require("./createUser");
8
9
  const deleteRole_1 = require("./deleteRole");
9
10
  const deleteScope_1 = require("./deleteScope");
11
+ const deleteUser_1 = require("./deleteUser");
10
12
  const getRoles_1 = require("./getRoles");
11
13
  const getScopes_1 = require("./getScopes");
14
+ const getUsers_1 = require("./getUsers");
15
+ const updateUser_1 = require("./updateUser");
12
16
  const upsertRole_1 = require("./upsertRole");
13
17
  const newManagementClient = async (config) => {
14
18
  config = (0, config_1.useConfigDefaults)(config);
@@ -35,6 +39,18 @@ const newManagementClient = async (config) => {
35
39
  const getRoles = async (tenantId) => {
36
40
  return await (0, getRoles_1.getAllRoles)(tenantId, serviceClient);
37
41
  };
42
+ const createUser = async (tenantId, email, assignedRoleIds, login = "", displayName = "", password = "", active = false, blockedUntil = new Date(0)) => {
43
+ return await (0, createUser_1.createNewUser)(tenantId, login, email, displayName, password, assignedRoleIds, active, blockedUntil, serviceClient);
44
+ };
45
+ const updateUser = async (tenantId, id, email, assignedRoleIds, login = "", displayName = "", password = "", active = false, blockedUntil = new Date(0)) => {
46
+ return await (0, updateUser_1.updateExistingUser)(tenantId, id, login, email, displayName, password, assignedRoleIds, active, blockedUntil, serviceClient);
47
+ };
48
+ const deleteUser = async (tenantId, id) => {
49
+ return await (0, deleteUser_1.deleteExistingUser)(tenantId, id, serviceClient);
50
+ };
51
+ const getUsers = async (tenantId) => {
52
+ return await (0, getUsers_1.getAllUsers)(tenantId, serviceClient);
53
+ };
38
54
  const close = async () => {
39
55
  serviceClient.close();
40
56
  };
@@ -45,6 +61,10 @@ const newManagementClient = async (config) => {
45
61
  upsertRole,
46
62
  deleteRole,
47
63
  getRoles,
64
+ createUser,
65
+ updateUser,
66
+ deleteUser,
67
+ getUsers,
48
68
  close,
49
69
  };
50
70
  };
@@ -0,0 +1,6 @@
1
+ import { ManagementServiceClient } from "@fraym/auth-proto";
2
+ export interface CreateUserResponse {
3
+ id: string;
4
+ setInitialPasswordToken: string;
5
+ }
6
+ export declare const createNewUser: (tenantId: string, login: string, email: string, displayName: string, password: string, assignedRoleIds: string[], active: boolean, blockedUntil: Date, serviceClient: ManagementServiceClient) => Promise<CreateUserResponse>;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createNewUser = void 0;
4
+ const createNewUser = async (tenantId, login, email, displayName, password, assignedRoleIds, active, blockedUntil, serviceClient) => {
5
+ return new Promise((resolve, reject) => {
6
+ serviceClient.createUser({
7
+ tenantId,
8
+ login,
9
+ email,
10
+ displayName,
11
+ password,
12
+ active,
13
+ assignedRoleIds,
14
+ blockedUntil: blockedUntil.getTime(),
15
+ }, (error, response) => {
16
+ if (error) {
17
+ reject(error.message);
18
+ return;
19
+ }
20
+ resolve({
21
+ id: response.id,
22
+ setInitialPasswordToken: response.setInitialPasswordToken,
23
+ });
24
+ });
25
+ });
26
+ };
27
+ exports.createNewUser = createNewUser;
@@ -0,0 +1,2 @@
1
+ import { ManagementServiceClient } from "@fraym/auth-proto";
2
+ export declare const deleteExistingUser: (tenantId: string, id: string, serviceClient: ManagementServiceClient) => Promise<void>;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deleteExistingUser = void 0;
4
+ const deleteExistingUser = async (tenantId, id, serviceClient) => {
5
+ return new Promise((resolve, reject) => {
6
+ serviceClient.deleteUser({
7
+ tenantId,
8
+ id,
9
+ }, error => {
10
+ if (error) {
11
+ reject(error.message);
12
+ return;
13
+ }
14
+ resolve();
15
+ });
16
+ });
17
+ };
18
+ exports.deleteExistingUser = deleteExistingUser;
@@ -0,0 +1,13 @@
1
+ import { ManagementServiceClient } from "@fraym/auth-proto";
2
+ export interface User {
3
+ id: string;
4
+ login: string;
5
+ email: string;
6
+ displayName: string;
7
+ assignedRoleIds: string[];
8
+ active: boolean;
9
+ failedAttempts: number;
10
+ lastAttempt: number;
11
+ blockedUntil: number;
12
+ }
13
+ export declare const getAllUsers: (tenantId: string, serviceClient: ManagementServiceClient) => Promise<User[]>;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAllUsers = void 0;
4
+ const getAllUsers = async (tenantId, serviceClient) => {
5
+ return new Promise((resolve, reject) => {
6
+ serviceClient.getUsers({
7
+ tenantId,
8
+ }, (error, response) => {
9
+ if (error) {
10
+ reject(error.message);
11
+ return;
12
+ }
13
+ resolve(response.users);
14
+ });
15
+ });
16
+ };
17
+ exports.getAllUsers = getAllUsers;
@@ -0,0 +1,2 @@
1
+ import { ManagementServiceClient } from "@fraym/auth-proto";
2
+ export declare const updateExistingUser: (tenantId: string, id: string, login: string, email: string, displayName: string, password: string, assignedRoleIds: string[], active: boolean, blockedUntil: Date, serviceClient: ManagementServiceClient) => Promise<void>;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateExistingUser = void 0;
4
+ const updateExistingUser = async (tenantId, id, login, email, displayName, password, assignedRoleIds, active, blockedUntil, serviceClient) => {
5
+ return new Promise((resolve, reject) => {
6
+ serviceClient.updateUser({
7
+ tenantId,
8
+ id,
9
+ login,
10
+ email,
11
+ displayName,
12
+ password,
13
+ active,
14
+ assignedRoleIds,
15
+ blockedUntil: blockedUntil.getTime(),
16
+ }, error => {
17
+ if (error) {
18
+ reject(error.message);
19
+ return;
20
+ }
21
+ resolve();
22
+ });
23
+ });
24
+ };
25
+ exports.updateExistingUser = updateExistingUser;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fraym/auth",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "license": "UNLICENSED",
5
5
  "homepage": "https://github.com/fraym/auth-nodejs",
6
6
  "repository": {
@@ -27,7 +27,7 @@
27
27
  "auth": "dist/cmd/auth.js"
28
28
  },
29
29
  "dependencies": {
30
- "@fraym/auth-proto": "^0.4.0",
30
+ "@fraym/auth-proto": "^0.5.1",
31
31
  "@graphql-tools/graphql-file-loader": "^7.5.11",
32
32
  "@graphql-tools/load": "^7.8.6",
33
33
  "@grpc/grpc-js": "1.7.2",