@envelop/auth0 9.1.1 → 9.2.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/LICENSE +3 -1
- package/cjs/index.js +15 -17
- package/esm/index.js +15 -17
- package/package.json +5 -4
- package/typings/index.d.cts +2 -2
- package/typings/index.d.ts +2 -2
package/LICENSE
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2020
|
|
3
|
+
Copyright (c) 2018-2020 Graphcool
|
|
4
|
+
Copyright (c) 2020-2021 Prisma
|
|
5
|
+
Copyright (c) 2021- The Guild
|
|
4
6
|
|
|
5
7
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
8
|
of this software and associated documentation files (the "Software"), to deal
|
package/cjs/index.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.useAuth0 = exports.UnauthenticatedError = void 0;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
|
-
/* eslint-disable dot-notation */
|
|
7
6
|
const jsonwebtoken_1 = tslib_1.__importDefault(require("jsonwebtoken"));
|
|
8
7
|
const JwksRsa = tslib_1.__importStar(require("jwks-rsa"));
|
|
9
8
|
const promise_helpers_1 = require("@whatwg-node/promise-helpers");
|
|
@@ -26,40 +25,39 @@ const useAuth0 = (options) => {
|
|
|
26
25
|
((ctx = {}) => {
|
|
27
26
|
const req = ctx['req'] || ctx['request'] || {};
|
|
28
27
|
const headers = req.headers || ctx['headers'] || null;
|
|
29
|
-
if (
|
|
30
|
-
console.warn(`useAuth0 plugin unable to locate your request or headers on the execution context. Please make sure to pass that, or provide custom "extractTokenFn" function.`);
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
28
|
+
if (headers) {
|
|
33
29
|
let authHeader = null;
|
|
34
30
|
if (headers[headerName] && typeof headers[headerName] === 'string') {
|
|
35
31
|
authHeader = headers[headerName] || null;
|
|
36
32
|
}
|
|
37
|
-
else if (headers.get && headers.has
|
|
33
|
+
else if (headers.get && headers.has?.(headerName)) {
|
|
38
34
|
authHeader = headers.get(headerName) || null;
|
|
39
35
|
}
|
|
40
36
|
if (authHeader === null) {
|
|
41
37
|
return null;
|
|
42
38
|
}
|
|
43
39
|
const split = authHeader.split(' ');
|
|
44
|
-
if (split.length
|
|
45
|
-
throw new Error(`Invalid value provided for header "${headerName}"!`);
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
40
|
+
if (split.length === 2) {
|
|
48
41
|
const [type, value] = split;
|
|
49
|
-
if (type
|
|
50
|
-
throw new Error(`Unsupported token type provided: "${type}"!`);
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
42
|
+
if (type === tokenType) {
|
|
53
43
|
return value;
|
|
54
44
|
}
|
|
45
|
+
throw new Error(`Unsupported token type provided: "${type}"!`);
|
|
55
46
|
}
|
|
47
|
+
else {
|
|
48
|
+
throw new Error(`Invalid value provided for header "${headerName}"!`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
console.warn(`useAuth0 plugin unable to locate your request or headers on the execution context. Please make sure to pass that, or provide custom "extractTokenFn" function.`);
|
|
56
53
|
}
|
|
57
54
|
return null;
|
|
58
55
|
});
|
|
59
56
|
const verifyToken = (token) => {
|
|
60
57
|
const decodedToken = decode(token, { complete: true, ...options.jwtDecodeOptions }) || {};
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
const kid = decodedToken?.['header']?.kid;
|
|
59
|
+
if (kid) {
|
|
60
|
+
return (0, promise_helpers_1.handleMaybePromise)(() => jkwsClient.getSigningKey(kid), secret => {
|
|
63
61
|
const signingKey = secret.getPublicKey();
|
|
64
62
|
const decoded = verify(token, signingKey, {
|
|
65
63
|
algorithms: ['RS256'],
|
|
@@ -82,7 +80,7 @@ const useAuth0 = (options) => {
|
|
|
82
80
|
});
|
|
83
81
|
});
|
|
84
82
|
}
|
|
85
|
-
|
|
83
|
+
if (options.preventUnauthenticatedAccess) {
|
|
86
84
|
throw new UnauthenticatedError(`Unauthenticated!`);
|
|
87
85
|
}
|
|
88
86
|
}, e => {
|
package/esm/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
|
-
/* eslint-disable dot-notation */
|
|
3
2
|
import jwtPkg from 'jsonwebtoken';
|
|
4
3
|
import * as JwksRsa from 'jwks-rsa';
|
|
5
4
|
import { handleMaybePromise } from '@whatwg-node/promise-helpers';
|
|
@@ -21,40 +20,39 @@ export const useAuth0 = (options) => {
|
|
|
21
20
|
((ctx = {}) => {
|
|
22
21
|
const req = ctx['req'] || ctx['request'] || {};
|
|
23
22
|
const headers = req.headers || ctx['headers'] || null;
|
|
24
|
-
if (
|
|
25
|
-
console.warn(`useAuth0 plugin unable to locate your request or headers on the execution context. Please make sure to pass that, or provide custom "extractTokenFn" function.`);
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
23
|
+
if (headers) {
|
|
28
24
|
let authHeader = null;
|
|
29
25
|
if (headers[headerName] && typeof headers[headerName] === 'string') {
|
|
30
26
|
authHeader = headers[headerName] || null;
|
|
31
27
|
}
|
|
32
|
-
else if (headers.get && headers.has
|
|
28
|
+
else if (headers.get && headers.has?.(headerName)) {
|
|
33
29
|
authHeader = headers.get(headerName) || null;
|
|
34
30
|
}
|
|
35
31
|
if (authHeader === null) {
|
|
36
32
|
return null;
|
|
37
33
|
}
|
|
38
34
|
const split = authHeader.split(' ');
|
|
39
|
-
if (split.length
|
|
40
|
-
throw new Error(`Invalid value provided for header "${headerName}"!`);
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
35
|
+
if (split.length === 2) {
|
|
43
36
|
const [type, value] = split;
|
|
44
|
-
if (type
|
|
45
|
-
throw new Error(`Unsupported token type provided: "${type}"!`);
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
37
|
+
if (type === tokenType) {
|
|
48
38
|
return value;
|
|
49
39
|
}
|
|
40
|
+
throw new Error(`Unsupported token type provided: "${type}"!`);
|
|
50
41
|
}
|
|
42
|
+
else {
|
|
43
|
+
throw new Error(`Invalid value provided for header "${headerName}"!`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
console.warn(`useAuth0 plugin unable to locate your request or headers on the execution context. Please make sure to pass that, or provide custom "extractTokenFn" function.`);
|
|
51
48
|
}
|
|
52
49
|
return null;
|
|
53
50
|
});
|
|
54
51
|
const verifyToken = (token) => {
|
|
55
52
|
const decodedToken = decode(token, { complete: true, ...options.jwtDecodeOptions }) || {};
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
const kid = decodedToken?.['header']?.kid;
|
|
54
|
+
if (kid) {
|
|
55
|
+
return handleMaybePromise(() => jkwsClient.getSigningKey(kid), secret => {
|
|
58
56
|
const signingKey = secret.getPublicKey();
|
|
59
57
|
const decoded = verify(token, signingKey, {
|
|
60
58
|
algorithms: ['RS256'],
|
|
@@ -77,7 +75,7 @@ export const useAuth0 = (options) => {
|
|
|
77
75
|
});
|
|
78
76
|
});
|
|
79
77
|
}
|
|
80
|
-
|
|
78
|
+
if (options.preventUnauthenticatedAccess) {
|
|
81
79
|
throw new UnauthenticatedError(`Unauthenticated!`);
|
|
82
80
|
}
|
|
83
81
|
}, e => {
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/auth0",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.2.1",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@envelop/core": "^5.
|
|
6
|
+
"@envelop/core": "^5.6.1"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"@whatwg-node/promise-helpers": "^1.2.4",
|
|
@@ -13,9 +13,10 @@
|
|
|
13
13
|
},
|
|
14
14
|
"repository": {
|
|
15
15
|
"type": "git",
|
|
16
|
-
"url": "https://github.com/graphql-hive/
|
|
17
|
-
"directory": "packages/plugins/auth0"
|
|
16
|
+
"url": "https://github.com/graphql-hive/graphql-yoga.git",
|
|
17
|
+
"directory": "packages/envelop/plugins/auth0"
|
|
18
18
|
},
|
|
19
|
+
"homepage": "https://github.com/graphql-hive/graphql-yoga/tree/main/packages/envelop/plugins/auth0#readme",
|
|
19
20
|
"author": "Dotan Simha <dotansimha@gmail.com>",
|
|
20
21
|
"license": "MIT",
|
|
21
22
|
"engines": {
|
package/typings/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DecodeOptions, VerifyOptions } from 'jsonwebtoken';
|
|
1
|
+
import type { DecodeOptions, VerifyOptions } from 'jsonwebtoken';
|
|
2
2
|
import * as JwksRsa from 'jwks-rsa';
|
|
3
|
-
import { Plugin } from '@envelop/core';
|
|
3
|
+
import type { Plugin } from '@envelop/core';
|
|
4
4
|
export type Auth0PluginOptions = {
|
|
5
5
|
domain: string;
|
|
6
6
|
audience: VerifyOptions['audience'];
|
package/typings/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DecodeOptions, VerifyOptions } from 'jsonwebtoken';
|
|
1
|
+
import type { DecodeOptions, VerifyOptions } from 'jsonwebtoken';
|
|
2
2
|
import * as JwksRsa from 'jwks-rsa';
|
|
3
|
-
import { Plugin } from '@envelop/core';
|
|
3
|
+
import type { Plugin } from '@envelop/core';
|
|
4
4
|
export type Auth0PluginOptions = {
|
|
5
5
|
domain: string;
|
|
6
6
|
audience: VerifyOptions['audience'];
|