@envelop/auth0 2.0.0 → 2.0.2-alpha-7ca7cb8.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.
Files changed (3) hide show
  1. package/index.js +20 -11
  2. package/index.mjs +20 -11
  3. package/package.json +2 -2
package/index.js CHANGED
@@ -4,10 +4,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
6
 
7
+ const core = require('@envelop/core');
7
8
  const JwksRsa = require('jwks-rsa');
8
9
  const jwtPkg = _interopDefault(require('jsonwebtoken'));
9
10
  const graphql = require('graphql');
10
11
 
12
+ /* eslint-disable no-console */
11
13
  const { decode, verify } = jwtPkg;
12
14
  class UnauthenticatedError extends graphql.GraphQLError {
13
15
  }
@@ -30,20 +32,27 @@ const useAuth0 = (options) => {
30
32
  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
33
  }
32
34
  else {
35
+ let authHeader = null;
33
36
  if (headers[headerName] && typeof headers[headerName] === 'string') {
34
- const authHeader = headers[headerName] || '';
35
- const split = authHeader.split(' ');
36
- if (split.length !== 2) {
37
- throw new Error(`Invalid value provided for header "${headerName}"!`);
37
+ authHeader = headers[headerName] || null;
38
+ }
39
+ else if (headers.get && headers.has && headers.has(headerName)) {
40
+ authHeader = headers.get(headerName) || null;
41
+ }
42
+ if (authHeader === null) {
43
+ return null;
44
+ }
45
+ const split = authHeader.split(' ');
46
+ if (split.length !== 2) {
47
+ throw new core.EnvelopError(`Invalid value provided for header "${headerName}"!`);
48
+ }
49
+ else {
50
+ const [type, value] = split;
51
+ if (type !== tokenType) {
52
+ throw new core.EnvelopError(`Unsupported token type provided: "${type}"!`);
38
53
  }
39
54
  else {
40
- const [type, value] = split;
41
- if (type !== tokenType) {
42
- throw new Error(`Unsupported token type provided: ${type}!`);
43
- }
44
- else {
45
- return value;
46
- }
55
+ return value;
47
56
  }
48
57
  }
49
58
  }
package/index.mjs CHANGED
@@ -1,7 +1,9 @@
1
+ import { EnvelopError } from '@envelop/core';
1
2
  import { JwksClient } from 'jwks-rsa';
2
3
  import jwtPkg from 'jsonwebtoken';
3
4
  import { GraphQLError } from 'graphql';
4
5
 
6
+ /* eslint-disable no-console */
5
7
  const { decode, verify } = jwtPkg;
6
8
  class UnauthenticatedError extends GraphQLError {
7
9
  }
@@ -24,20 +26,27 @@ const useAuth0 = (options) => {
24
26
  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.`);
25
27
  }
26
28
  else {
29
+ let authHeader = null;
27
30
  if (headers[headerName] && typeof headers[headerName] === 'string') {
28
- const authHeader = headers[headerName] || '';
29
- const split = authHeader.split(' ');
30
- if (split.length !== 2) {
31
- throw new Error(`Invalid value provided for header "${headerName}"!`);
31
+ authHeader = headers[headerName] || null;
32
+ }
33
+ else if (headers.get && headers.has && headers.has(headerName)) {
34
+ authHeader = headers.get(headerName) || null;
35
+ }
36
+ if (authHeader === null) {
37
+ return null;
38
+ }
39
+ const split = authHeader.split(' ');
40
+ if (split.length !== 2) {
41
+ throw new EnvelopError(`Invalid value provided for header "${headerName}"!`);
42
+ }
43
+ else {
44
+ const [type, value] = split;
45
+ if (type !== tokenType) {
46
+ throw new EnvelopError(`Unsupported token type provided: "${type}"!`);
32
47
  }
33
48
  else {
34
- const [type, value] = split;
35
- if (type !== tokenType) {
36
- throw new Error(`Unsupported token type provided: ${type}!`);
37
- }
38
- else {
39
- return value;
40
- }
49
+ return value;
41
50
  }
42
51
  }
43
52
  }
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@envelop/auth0",
3
- "version": "2.0.0",
3
+ "version": "2.0.2-alpha-7ca7cb8.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@envelop/core": "^1.7.0",
6
+ "@envelop/core": "1.7.2-alpha-7ca7cb8.0",
7
7
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
8
8
  },
9
9
  "dependencies": {