@fraym/auth 0.2.0 → 0.3.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
|
@@ -80,8 +80,10 @@ const roles = await managementClient.getRoles("TENANT_ID");
|
|
|
80
80
|
|
|
81
81
|
## Upsert a role
|
|
82
82
|
|
|
83
|
+
You can create roles without providing a role-id. The id of the new role will be returned:
|
|
84
|
+
|
|
83
85
|
```typescript
|
|
84
|
-
await managementClient.upsertRole("TENANT_ID",
|
|
86
|
+
const roleId = await managementClient.upsertRole("TENANT_ID", [
|
|
85
87
|
{
|
|
86
88
|
scopeName: "PERMISSION_NAME",
|
|
87
89
|
// optional: clientId: If none is given the default client will be used
|
|
@@ -89,6 +91,21 @@ await managementClient.upsertRole("TENANT_ID", "ROLE_ID", [
|
|
|
89
91
|
]);
|
|
90
92
|
```
|
|
91
93
|
|
|
94
|
+
You can also upsert a role by providing the role-id:
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
const roleId = await managementClient.upsertRole(
|
|
98
|
+
"TENANT_ID",
|
|
99
|
+
[
|
|
100
|
+
{
|
|
101
|
+
scopeName: "PERMISSION_NAME",
|
|
102
|
+
// optional: clientId: If none is given the default client will be used
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
"ROLE_ID"
|
|
106
|
+
);
|
|
107
|
+
```
|
|
108
|
+
|
|
92
109
|
## Delete a role
|
|
93
110
|
|
|
94
111
|
```typescript
|
package/dist/cmd/auth.js
CHANGED
|
@@ -59,7 +59,6 @@ const migratePermissions = async (permissions, serverAddress) => {
|
|
|
59
59
|
if (permissionsToCreate.length > 0) {
|
|
60
60
|
console.log(`Creating ${permissionsToCreate.length} permissions: ${permissionsToCreate}...`);
|
|
61
61
|
for (let i = 0; i < permissionsToCreate.length; i++) {
|
|
62
|
-
console.log("i", i);
|
|
63
62
|
await managementClient.createScope(permissionsToCreate[i]);
|
|
64
63
|
}
|
|
65
64
|
console.log(`Created ${permissionsToCreate.length} permissions`);
|
|
@@ -67,7 +66,6 @@ const migratePermissions = async (permissions, serverAddress) => {
|
|
|
67
66
|
if (permissionsToDelete.length > 0) {
|
|
68
67
|
console.log(`Removing ${permissionsToDelete.length} permissions: ${permissionsToDelete}...`);
|
|
69
68
|
for (let i = 0; i < permissionsToDelete.length; i++) {
|
|
70
|
-
console.log("i", i);
|
|
71
69
|
await managementClient.deleteScope(permissionsToDelete[i]);
|
|
72
70
|
}
|
|
73
71
|
console.log(`Removed ${permissionsToDelete.length} permissions`);
|
|
@@ -7,7 +7,7 @@ export interface ManagementClient {
|
|
|
7
7
|
createScope: (name: string, clientId?: string) => Promise<void>;
|
|
8
8
|
deleteScope: (name: string, clientId?: string) => Promise<void>;
|
|
9
9
|
getScopes: (clientId?: string) => Promise<string[]>;
|
|
10
|
-
upsertRole: (tenantId: string,
|
|
10
|
+
upsertRole: (tenantId: string, allowedScopes: UpsertRoleScope[], id?: string) => Promise<string>;
|
|
11
11
|
deleteRole: (tenantId: string, id: string) => Promise<void>;
|
|
12
12
|
getRoles: (tenantId: string) => Promise<Role[]>;
|
|
13
13
|
createUser: (tenantId: string, email: string, assignedRoleIds: string[], login?: string, displayName?: string, password?: string, active?: boolean, blockedUntil?: Date) => Promise<CreateUserResponse>;
|
|
@@ -30,7 +30,7 @@ const newManagementClient = async (config) => {
|
|
|
30
30
|
const getScopes = async (clientId = "") => {
|
|
31
31
|
return await (0, getScopes_1.getAllScopes)(clientId, serviceClient);
|
|
32
32
|
};
|
|
33
|
-
const upsertRole = async (tenantId,
|
|
33
|
+
const upsertRole = async (tenantId, allowedScopes, id = "") => {
|
|
34
34
|
return await (0, upsertRole_1.createOrUpdateRole)(tenantId, id, allowedScopes, serviceClient);
|
|
35
35
|
};
|
|
36
36
|
const deleteRole = async (tenantId, id) => {
|
|
@@ -3,4 +3,4 @@ export interface UpsertRoleScope {
|
|
|
3
3
|
scopeName: string;
|
|
4
4
|
clientId?: string;
|
|
5
5
|
}
|
|
6
|
-
export declare const createOrUpdateRole: (tenantId: string, id: string, allowedScopes: UpsertRoleScope[], serviceClient: ManagementServiceClient) => Promise<
|
|
6
|
+
export declare const createOrUpdateRole: (tenantId: string, id: string, allowedScopes: UpsertRoleScope[], serviceClient: ManagementServiceClient) => Promise<string>;
|
|
@@ -13,12 +13,12 @@ const createOrUpdateRole = async (tenantId, id, allowedScopes, serviceClient) =>
|
|
|
13
13
|
clientId: (_a = scope.clientId) !== null && _a !== void 0 ? _a : "",
|
|
14
14
|
};
|
|
15
15
|
}),
|
|
16
|
-
}, error => {
|
|
16
|
+
}, (error, response) => {
|
|
17
17
|
if (error) {
|
|
18
18
|
reject(error.message);
|
|
19
19
|
return;
|
|
20
20
|
}
|
|
21
|
-
resolve();
|
|
21
|
+
resolve(response.id);
|
|
22
22
|
});
|
|
23
23
|
});
|
|
24
24
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fraym/auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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.
|
|
30
|
+
"@fraym/auth-proto": "^0.6.0",
|
|
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",
|