@fraym/auth 0.6.0 → 0.7.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 +0 -54
- package/dist/management/client.js +2 -2
- package/dist/management/createUser.d.ts +2 -2
- package/dist/management/deleteRole.d.ts +2 -2
- package/dist/management/deleteUser.d.ts +2 -2
- package/dist/management/getRoles.d.ts +2 -2
- package/dist/management/getUsers.d.ts +2 -2
- package/dist/management/updateUser.d.ts +2 -2
- package/dist/management/upsertRole.d.ts +2 -2
- package/dist/util/token.js +6 -2
- package/package.json +16 -13
package/README.md
CHANGED
|
@@ -15,34 +15,12 @@ There is a sandbox available at `http://auth:3000/management/graphql/sandbox`.
|
|
|
15
15
|
|
|
16
16
|
You need to add the `Tenant-Id` header in order to use the graphQL Endpoint and the sandbox.
|
|
17
17
|
|
|
18
|
-
## CLI command
|
|
19
|
-
|
|
20
|
-
Use the `auth` cli command to automatically apply your permissions to the auth service.
|
|
21
|
-
|
|
22
|
-
You can specify the address (and port) of the auth service instance you use in the `AUTH_SERVER_ADDRESS` env variable (default: `127.0.0.1:9000`).
|
|
23
|
-
|
|
24
|
-
In case of scopes api you need to configure the HTTP api:
|
|
25
|
-
|
|
26
|
-
- `AUTH_HTTP_SERVER_ADDRESS`: Http api url of the auth service (default: `http://127.0.0.1`)
|
|
27
|
-
- `AUTH_HTTP_API_TOKEN`: The value of that token has to match the token configured in the auth service
|
|
28
|
-
|
|
29
|
-
The needed schema for auth is a simple enum containing all your permissions. Example:
|
|
30
|
-
|
|
31
|
-
```graphql
|
|
32
|
-
enum Permission {
|
|
33
|
-
USER_READ
|
|
34
|
-
USER_WRITE
|
|
35
|
-
}
|
|
36
|
-
```
|
|
37
|
-
|
|
38
18
|
### Config
|
|
39
19
|
|
|
40
20
|
Use a `.env` file or env variables to configure cte clients and the command:
|
|
41
21
|
|
|
42
22
|
```env
|
|
43
23
|
AUTH_SERVER_ADDRESS=127.0.0.1:9000
|
|
44
|
-
AUTH_HTTP_SERVER_ADDRESS=http://127.0.0.1
|
|
45
|
-
AUTH_HTTP_API_TOKEN=
|
|
46
24
|
```
|
|
47
25
|
|
|
48
26
|
## JWT functions
|
|
@@ -93,42 +71,10 @@ Parameters:
|
|
|
93
71
|
|
|
94
72
|
### Create the client
|
|
95
73
|
|
|
96
|
-
management client:
|
|
97
|
-
|
|
98
74
|
```typescript
|
|
99
75
|
const managementClient = await newManagementClient();
|
|
100
76
|
```
|
|
101
77
|
|
|
102
|
-
## Get all scopes (permissions)
|
|
103
|
-
|
|
104
|
-
The `clientId` paramenter is optional. If none is given the default client will be used.
|
|
105
|
-
|
|
106
|
-
```typescript
|
|
107
|
-
const scopes = await managementClient.getScopes();
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
Note: you need to configure `AUTH_HTTP_SERVER_ADDRESS` and `AUTH_HTTP_API_TOKEN` to use this function.
|
|
111
|
-
|
|
112
|
-
## Create a scope (permission)
|
|
113
|
-
|
|
114
|
-
The `clientId` paramenter is optional. If none is given the default client will be used.
|
|
115
|
-
|
|
116
|
-
```typescript
|
|
117
|
-
await managementClient.createScope("PERMISSION_NAME");
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
Note: you need to configure `AUTH_HTTP_SERVER_ADDRESS` and `AUTH_HTTP_API_TOKEN` to use this function.
|
|
121
|
-
|
|
122
|
-
## Delete a scope (permission)
|
|
123
|
-
|
|
124
|
-
The `clientId` paramenter is optional. If none is given the default client will be used.
|
|
125
|
-
|
|
126
|
-
```typescript
|
|
127
|
-
await managementClient.deleteScope("PERMISSION_NAME");
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
Note: you need to configure `AUTH_HTTP_SERVER_ADDRESS` and `AUTH_HTTP_API_TOKEN` to use this function.
|
|
131
|
-
|
|
132
78
|
## Get all roles
|
|
133
79
|
|
|
134
80
|
```typescript
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.newManagementClient = void 0;
|
|
4
|
-
const
|
|
4
|
+
const management_1 = require("@fraym/proto/freym/auth/management");
|
|
5
5
|
const grpc_js_1 = require("@grpc/grpc-js");
|
|
6
6
|
const config_1 = require("../config/config");
|
|
7
7
|
const createUser_1 = require("./createUser");
|
|
@@ -13,7 +13,7 @@ const updateUser_1 = require("./updateUser");
|
|
|
13
13
|
const upsertRole_1 = require("./upsertRole");
|
|
14
14
|
const newManagementClient = async (config) => {
|
|
15
15
|
const currentConfig = (0, config_1.useConfigDefaults)(config);
|
|
16
|
-
const serviceClient = new
|
|
16
|
+
const serviceClient = new management_1.ServiceClient(currentConfig.serverAddress, grpc_js_1.credentials.createInsecure(), {
|
|
17
17
|
"grpc.keepalive_time_ms": currentConfig.keepaliveInterval,
|
|
18
18
|
"grpc.keepalive_timeout_ms": currentConfig.keepaliveTimeout,
|
|
19
19
|
"grpc.keepalive_permit_without_calls": 1,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ServiceClient } from "@fraym/proto/freym/auth/management";
|
|
2
2
|
export interface CreateUserResponse {
|
|
3
3
|
id: string;
|
|
4
4
|
setInitialPasswordToken: string;
|
|
5
5
|
}
|
|
6
|
-
export declare const createNewUser: (tenantId: string, login: string, email: string, displayName: string, password: string, assignedRoleIds: string[], active: boolean, blockedUntil: Date, serviceClient:
|
|
6
|
+
export declare const createNewUser: (tenantId: string, login: string, email: string, displayName: string, password: string, assignedRoleIds: string[], active: boolean, blockedUntil: Date, serviceClient: ServiceClient) => Promise<CreateUserResponse>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const deleteExistingRole: (tenantId: string, id: string, serviceClient:
|
|
1
|
+
import { ServiceClient } from "@fraym/proto/freym/auth/management";
|
|
2
|
+
export declare const deleteExistingRole: (tenantId: string, id: string, serviceClient: ServiceClient) => Promise<void>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const deleteExistingUser: (tenantId: string, id: string, serviceClient:
|
|
1
|
+
import { ServiceClient } from "@fraym/proto/freym/auth/management";
|
|
2
|
+
export declare const deleteExistingUser: (tenantId: string, id: string, serviceClient: ServiceClient) => Promise<void>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ServiceClient } from "@fraym/proto/freym/auth/management";
|
|
2
2
|
export interface Role {
|
|
3
3
|
id: string;
|
|
4
4
|
allowedScopes: RoleScope[];
|
|
@@ -7,4 +7,4 @@ export interface RoleScope {
|
|
|
7
7
|
clientId: string;
|
|
8
8
|
scopeName: string;
|
|
9
9
|
}
|
|
10
|
-
export declare const getAllRoles: (tenantId: string, serviceClient:
|
|
10
|
+
export declare const getAllRoles: (tenantId: string, serviceClient: ServiceClient) => Promise<Role[]>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ServiceClient } from "@fraym/proto/freym/auth/management";
|
|
2
2
|
export interface User {
|
|
3
3
|
id: string;
|
|
4
4
|
login: string;
|
|
@@ -10,4 +10,4 @@ export interface User {
|
|
|
10
10
|
lastAttempt: number;
|
|
11
11
|
blockedUntil: number;
|
|
12
12
|
}
|
|
13
|
-
export declare const getAllUsers: (tenantId: string, serviceClient:
|
|
13
|
+
export declare const getAllUsers: (tenantId: string, serviceClient: ServiceClient) => Promise<User[]>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const updateExistingUser: (tenantId: string, id: string, login: string, email: string, displayName: string, password: string, assignedRoleIds: string[], active: boolean, blockedUntil: Date, serviceClient:
|
|
1
|
+
import { ServiceClient } from "@fraym/proto/freym/auth/management";
|
|
2
|
+
export declare const updateExistingUser: (tenantId: string, id: string, login: string, email: string, displayName: string, password: string, assignedRoleIds: string[], active: boolean, blockedUntil: Date, serviceClient: ServiceClient) => Promise<void>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ServiceClient } from "@fraym/proto/freym/auth/management";
|
|
2
2
|
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:
|
|
6
|
+
export declare const createOrUpdateRole: (tenantId: string, id: string, allowedScopes: UpsertRoleScope[], serviceClient: ServiceClient) => Promise<string>;
|
package/dist/util/token.js
CHANGED
|
@@ -26,7 +26,9 @@ exports.generateJwt = generateJwt;
|
|
|
26
26
|
const addDataToJwt = async (appSecret, token, data) => {
|
|
27
27
|
var _a;
|
|
28
28
|
const secret = new TextEncoder().encode(appSecret);
|
|
29
|
-
const { payload, protectedHeader } = await (0, jose_1.jwtVerify)(token, secret
|
|
29
|
+
const { payload, protectedHeader } = await (0, jose_1.jwtVerify)(token, secret, {
|
|
30
|
+
clockTolerance: "10 seconds",
|
|
31
|
+
});
|
|
30
32
|
if (!payload.exp) {
|
|
31
33
|
throw Error("expiration time is missing in JWT");
|
|
32
34
|
}
|
|
@@ -42,7 +44,9 @@ exports.addDataToJwt = addDataToJwt;
|
|
|
42
44
|
const getTokenData = async (appSecret, token, requireUserId = true) => {
|
|
43
45
|
var _a, _b, _c;
|
|
44
46
|
const secret = new TextEncoder().encode(appSecret);
|
|
45
|
-
const { payload } = await (0, jose_1.jwtVerify)(token, secret
|
|
47
|
+
const { payload } = await (0, jose_1.jwtVerify)(token, secret, {
|
|
48
|
+
clockTolerance: "10 seconds",
|
|
49
|
+
});
|
|
46
50
|
if (!payload.exp) {
|
|
47
51
|
throw Error("expiration time is missing in JWT");
|
|
48
52
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fraym/auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"homepage": "https://github.com/fraym/auth-nodejs",
|
|
6
6
|
"repository": {
|
|
@@ -21,25 +21,28 @@
|
|
|
21
21
|
"files": [
|
|
22
22
|
"dist/**/*"
|
|
23
23
|
],
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=16"
|
|
26
|
+
},
|
|
24
27
|
"main": "dist/index.js",
|
|
25
28
|
"types": "dist/index.d.ts",
|
|
26
29
|
"dependencies": {
|
|
27
|
-
"@fraym/
|
|
28
|
-
"@graphql-tools/graphql-file-loader": "^7.5.
|
|
29
|
-
"@graphql-tools/load": "^7.8.
|
|
30
|
-
"@grpc/grpc-js": "^1.
|
|
31
|
-
"dotenv": "^16.
|
|
32
|
-
"graphql": "^16.
|
|
33
|
-
"jose": "^4.
|
|
34
|
-
"yargs": "^17.
|
|
30
|
+
"@fraym/proto": "^0.2.0",
|
|
31
|
+
"@graphql-tools/graphql-file-loader": "^7.5.17",
|
|
32
|
+
"@graphql-tools/load": "^7.8.14",
|
|
33
|
+
"@grpc/grpc-js": "^1.9.3",
|
|
34
|
+
"dotenv": "^16.3.1",
|
|
35
|
+
"graphql": "^16.8.0",
|
|
36
|
+
"jose": "^4.14.6",
|
|
37
|
+
"yargs": "^17.7.2"
|
|
35
38
|
},
|
|
36
39
|
"devDependencies": {
|
|
37
40
|
"@becklyn/prettier": "^1.0.2",
|
|
38
41
|
"@types/uuid": "^8.3.4",
|
|
39
|
-
"@types/yargs": "^17.0.
|
|
40
|
-
"prettier": "^2.
|
|
41
|
-
"typescript": "^4.
|
|
42
|
-
"uuid": "^9.0.
|
|
42
|
+
"@types/yargs": "^17.0.24",
|
|
43
|
+
"prettier": "^2.8.8",
|
|
44
|
+
"typescript": "^4.9.5",
|
|
45
|
+
"uuid": "^9.0.1"
|
|
43
46
|
},
|
|
44
47
|
"prettier": "@becklyn/prettier"
|
|
45
48
|
}
|