@envelop/auth0 3.4.0 → 3.4.1-alpha-72027859.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 +14 -14
- package/cjs/index.js +5 -7
- package/esm/index.js +5 -7
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -14,32 +14,32 @@ We recommend using the [Adding Authentication with Auth0 guide](https://www.enve
|
|
|
14
14
|
4. Setup Envelop with that plugin:
|
|
15
15
|
|
|
16
16
|
```ts
|
|
17
|
-
import { envelop } from '@envelop/core'
|
|
18
|
-
import { useAuth0 } from '@envelop/auth0'
|
|
17
|
+
import { envelop } from '@envelop/core'
|
|
18
|
+
import { useAuth0 } from '@envelop/auth0'
|
|
19
19
|
|
|
20
20
|
const getEnveloped = envelop({
|
|
21
21
|
plugins: [
|
|
22
22
|
// ... other plugins ...
|
|
23
23
|
useAuth0({
|
|
24
|
-
onError: e => {
|
|
24
|
+
onError: e => {}, // In case of an error, you can override it and customize the error your client will get.
|
|
25
25
|
domain: 'YOUR_AUTH0_DOMAIN_HERE',
|
|
26
26
|
audience: 'YOUR_AUTH0_AUDIENCE_HERE',
|
|
27
27
|
headerName: 'authorization', // Name of the header
|
|
28
28
|
preventUnauthenticatedAccess: true, // If you need to have unauthenticated parts on your schema, make sure to disable that by setting it to `false` and the check it in your resolvers.
|
|
29
29
|
extendContextField: 'auth0', // The name of the field injected to your `context`
|
|
30
|
-
tokenType: 'Bearer'
|
|
31
|
-
})
|
|
32
|
-
]
|
|
33
|
-
})
|
|
30
|
+
tokenType: 'Bearer' // Type of token to expect in the header
|
|
31
|
+
})
|
|
32
|
+
]
|
|
33
|
+
})
|
|
34
34
|
```
|
|
35
35
|
|
|
36
36
|
5. Make sure to pass your request as part of the context building:
|
|
37
37
|
|
|
38
38
|
```ts
|
|
39
39
|
myHttpServer.on('request', async req => {
|
|
40
|
-
const { contextFactory } = getEnveloped({ req })
|
|
41
|
-
const contextValue = await contextFactory({ req })
|
|
42
|
-
})
|
|
40
|
+
const { contextFactory } = getEnveloped({ req })
|
|
41
|
+
const contextValue = await contextFactory({ req }) // Make sure to pass it here
|
|
42
|
+
})
|
|
43
43
|
```
|
|
44
44
|
|
|
45
45
|
> By default, this plugins looks for `req` or `request` properties in your base context. If you need to override it, please use `extractTokenFn` and you can customize it.
|
|
@@ -50,10 +50,10 @@ myHttpServer.on('request', async req => {
|
|
|
50
50
|
const myResolvers = {
|
|
51
51
|
Query: {
|
|
52
52
|
me: (root, args, context, info) => {
|
|
53
|
-
const auth0UserId = context.auth0.sub
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
53
|
+
const auth0UserId = context.auth0.sub
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
57
|
```
|
|
58
58
|
|
|
59
59
|
### API Reference
|
package/cjs/index.js
CHANGED
|
@@ -18,7 +18,7 @@ const useAuth0 = (options) => {
|
|
|
18
18
|
rateLimit: true,
|
|
19
19
|
jwksRequestsPerMinute: 5,
|
|
20
20
|
jwksUri: `https://${options.domain}/.well-known/jwks.json`,
|
|
21
|
-
...
|
|
21
|
+
...options.jwksClientOptions,
|
|
22
22
|
});
|
|
23
23
|
const contextField = options.extendContextField || '_auth0';
|
|
24
24
|
const tokenType = options.tokenType || 'Bearer';
|
|
@@ -58,7 +58,7 @@ const useAuth0 = (options) => {
|
|
|
58
58
|
return null;
|
|
59
59
|
});
|
|
60
60
|
const verifyToken = async (token) => {
|
|
61
|
-
const decodedToken = decode(token, { complete: true, ...
|
|
61
|
+
const decodedToken = decode(token, { complete: true, ...options.jwtDecodeOptions }) || {};
|
|
62
62
|
if (decodedToken && decodedToken.header && decodedToken.header.kid) {
|
|
63
63
|
const secret = await jkwsClient.getSigningKey(decodedToken.header.kid);
|
|
64
64
|
const signingKey = secret.getPublicKey();
|
|
@@ -66,7 +66,7 @@ const useAuth0 = (options) => {
|
|
|
66
66
|
algorithms: ['RS256'],
|
|
67
67
|
audience: options.audience,
|
|
68
68
|
issuer: `https://${options.domain}/`,
|
|
69
|
-
...
|
|
69
|
+
...options.jwtVerifyOptions,
|
|
70
70
|
});
|
|
71
71
|
return decoded;
|
|
72
72
|
}
|
|
@@ -82,10 +82,8 @@ const useAuth0 = (options) => {
|
|
|
82
82
|
[contextField]: decodedPayload,
|
|
83
83
|
});
|
|
84
84
|
}
|
|
85
|
-
else {
|
|
86
|
-
|
|
87
|
-
throw new UnauthenticatedError(`Unauthenticated!`);
|
|
88
|
-
}
|
|
85
|
+
else if (options.preventUnauthenticatedAccess) {
|
|
86
|
+
throw new UnauthenticatedError(`Unauthenticated!`);
|
|
89
87
|
}
|
|
90
88
|
}
|
|
91
89
|
catch (e) {
|
package/esm/index.js
CHANGED
|
@@ -13,7 +13,7 @@ export const useAuth0 = (options) => {
|
|
|
13
13
|
rateLimit: true,
|
|
14
14
|
jwksRequestsPerMinute: 5,
|
|
15
15
|
jwksUri: `https://${options.domain}/.well-known/jwks.json`,
|
|
16
|
-
...
|
|
16
|
+
...options.jwksClientOptions,
|
|
17
17
|
});
|
|
18
18
|
const contextField = options.extendContextField || '_auth0';
|
|
19
19
|
const tokenType = options.tokenType || 'Bearer';
|
|
@@ -53,7 +53,7 @@ export const useAuth0 = (options) => {
|
|
|
53
53
|
return null;
|
|
54
54
|
});
|
|
55
55
|
const verifyToken = async (token) => {
|
|
56
|
-
const decodedToken = decode(token, { complete: true, ...
|
|
56
|
+
const decodedToken = decode(token, { complete: true, ...options.jwtDecodeOptions }) || {};
|
|
57
57
|
if (decodedToken && decodedToken.header && decodedToken.header.kid) {
|
|
58
58
|
const secret = await jkwsClient.getSigningKey(decodedToken.header.kid);
|
|
59
59
|
const signingKey = secret.getPublicKey();
|
|
@@ -61,7 +61,7 @@ export const useAuth0 = (options) => {
|
|
|
61
61
|
algorithms: ['RS256'],
|
|
62
62
|
audience: options.audience,
|
|
63
63
|
issuer: `https://${options.domain}/`,
|
|
64
|
-
...
|
|
64
|
+
...options.jwtVerifyOptions,
|
|
65
65
|
});
|
|
66
66
|
return decoded;
|
|
67
67
|
}
|
|
@@ -77,10 +77,8 @@ export const useAuth0 = (options) => {
|
|
|
77
77
|
[contextField]: decodedPayload,
|
|
78
78
|
});
|
|
79
79
|
}
|
|
80
|
-
else {
|
|
81
|
-
|
|
82
|
-
throw new UnauthenticatedError(`Unauthenticated!`);
|
|
83
|
-
}
|
|
80
|
+
else if (options.preventUnauthenticatedAccess) {
|
|
81
|
+
throw new UnauthenticatedError(`Unauthenticated!`);
|
|
84
82
|
}
|
|
85
83
|
}
|
|
86
84
|
catch (e) {
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/auth0",
|
|
3
|
-
"version": "3.4.0",
|
|
3
|
+
"version": "3.4.1-alpha-72027859.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@envelop/core": "
|
|
6
|
+
"@envelop/core": "2.4.1-alpha-72027859.0",
|
|
7
7
|
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|