@fraym/auth 0.6.0 → 0.6.1
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/util/token.js +6 -2
- package/package.json +1 -1
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
|
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
|
}
|