@envelop/auth0 4.0.0-alpha-d0d0776.0 → 4.0.0-alpha-ccec0fc.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 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 => { ... }, // In case of an error, you can override it and customize the error your client will get.
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', // Type of token to expect in the header
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 }); // Make sure to pass it here
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
@@ -1,46 +1,24 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- const core = require('@envelop/core');
6
- const JwksRsa = require('jwks-rsa');
7
- const jwtPkg = require('jsonwebtoken');
8
- const graphql = require('graphql');
9
-
10
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
-
12
- function _interopNamespace(e) {
13
- if (e && e.__esModule) return e;
14
- const n = Object.create(null);
15
- if (e) {
16
- for (const k in e) {
17
- if (k !== 'default') {
18
- const d = Object.getOwnPropertyDescriptor(e, k);
19
- Object.defineProperty(n, k, d.get ? d : {
20
- enumerable: true,
21
- get: function () { return e[k]; }
22
- });
23
- }
24
- }
25
- }
26
- n["default"] = e;
27
- return Object.freeze(n);
28
- }
29
-
30
- const JwksRsa__namespace = /*#__PURE__*/_interopNamespace(JwksRsa);
31
- const jwtPkg__default = /*#__PURE__*/_interopDefaultLegacy(jwtPkg);
32
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useAuth0 = exports.UnauthenticatedError = void 0;
4
+ const tslib_1 = require("tslib");
33
5
  /* eslint-disable no-console */
34
- const { decode, verify } = jwtPkg__default["default"];
35
- class UnauthenticatedError extends graphql.GraphQLError {
6
+ /* eslint-disable dot-notation */
7
+ const core_1 = require("@envelop/core");
8
+ const JwksRsa = tslib_1.__importStar(require("jwks-rsa"));
9
+ const jsonwebtoken_1 = tslib_1.__importDefault(require("jsonwebtoken"));
10
+ const graphql_1 = require("@graphql-tools/graphql");
11
+ const { decode, verify } = jsonwebtoken_1.default;
12
+ class UnauthenticatedError extends graphql_1.GraphQLError {
36
13
  }
14
+ exports.UnauthenticatedError = UnauthenticatedError;
37
15
  const useAuth0 = (options) => {
38
- const jkwsClient = new JwksRsa__namespace.JwksClient({
16
+ const jkwsClient = new JwksRsa.JwksClient({
39
17
  cache: true,
40
18
  rateLimit: true,
41
19
  jwksRequestsPerMinute: 5,
42
20
  jwksUri: `https://${options.domain}/.well-known/jwks.json`,
43
- ...(options.jwksClientOptions || {}),
21
+ ...options.jwksClientOptions,
44
22
  });
45
23
  const contextField = options.extendContextField || '_auth0';
46
24
  const tokenType = options.tokenType || 'Bearer';
@@ -65,12 +43,12 @@ const useAuth0 = (options) => {
65
43
  }
66
44
  const split = authHeader.split(' ');
67
45
  if (split.length !== 2) {
68
- throw new core.EnvelopError(`Invalid value provided for header "${headerName}"!`);
46
+ throw new core_1.EnvelopError(`Invalid value provided for header "${headerName}"!`);
69
47
  }
70
48
  else {
71
49
  const [type, value] = split;
72
50
  if (type !== tokenType) {
73
- throw new core.EnvelopError(`Unsupported token type provided: "${type}"!`);
51
+ throw new core_1.EnvelopError(`Unsupported token type provided: "${type}"!`);
74
52
  }
75
53
  else {
76
54
  return value;
@@ -80,7 +58,7 @@ const useAuth0 = (options) => {
80
58
  return null;
81
59
  });
82
60
  const verifyToken = async (token) => {
83
- const decodedToken = decode(token, { complete: true, ...(options.jwtDecodeOptions || {}) }) || {};
61
+ const decodedToken = decode(token, { complete: true, ...options.jwtDecodeOptions }) || {};
84
62
  if (decodedToken && decodedToken.header && decodedToken.header.kid) {
85
63
  const secret = await jkwsClient.getSigningKey(decodedToken.header.kid);
86
64
  const signingKey = secret.getPublicKey();
@@ -88,7 +66,7 @@ const useAuth0 = (options) => {
88
66
  algorithms: ['RS256'],
89
67
  audience: options.audience,
90
68
  issuer: `https://${options.domain}/`,
91
- ...(options.jwtVerifyOptions || {}),
69
+ ...options.jwtVerifyOptions,
92
70
  });
93
71
  return decoded;
94
72
  }
@@ -104,10 +82,8 @@ const useAuth0 = (options) => {
104
82
  [contextField]: decodedPayload,
105
83
  });
106
84
  }
107
- else {
108
- if (options.preventUnauthenticatedAccess) {
109
- throw new UnauthenticatedError(`Unauthenticated!`);
110
- }
85
+ else if (options.preventUnauthenticatedAccess) {
86
+ throw new UnauthenticatedError(`Unauthenticated!`);
111
87
  }
112
88
  }
113
89
  catch (e) {
@@ -121,6 +97,4 @@ const useAuth0 = (options) => {
121
97
  },
122
98
  };
123
99
  };
124
-
125
- exports.UnauthenticatedError = UnauthenticatedError;
126
100
  exports.useAuth0 = useAuth0;
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -1,19 +1,19 @@
1
+ /* eslint-disable no-console */
2
+ /* eslint-disable dot-notation */
1
3
  import { EnvelopError } from '@envelop/core';
2
4
  import * as JwksRsa from 'jwks-rsa';
3
5
  import jwtPkg from 'jsonwebtoken';
4
- import { GraphQLError } from 'graphql';
5
-
6
- /* eslint-disable no-console */
6
+ import { GraphQLError } from '@graphql-tools/graphql';
7
7
  const { decode, verify } = jwtPkg;
8
- class UnauthenticatedError extends GraphQLError {
8
+ export class UnauthenticatedError extends GraphQLError {
9
9
  }
10
- const useAuth0 = (options) => {
10
+ export const useAuth0 = (options) => {
11
11
  const jkwsClient = new JwksRsa.JwksClient({
12
12
  cache: true,
13
13
  rateLimit: true,
14
14
  jwksRequestsPerMinute: 5,
15
15
  jwksUri: `https://${options.domain}/.well-known/jwks.json`,
16
- ...(options.jwksClientOptions || {}),
16
+ ...options.jwksClientOptions,
17
17
  });
18
18
  const contextField = options.extendContextField || '_auth0';
19
19
  const tokenType = options.tokenType || 'Bearer';
@@ -53,7 +53,7 @@ const useAuth0 = (options) => {
53
53
  return null;
54
54
  });
55
55
  const verifyToken = async (token) => {
56
- const decodedToken = decode(token, { complete: true, ...(options.jwtDecodeOptions || {}) }) || {};
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 @@ const useAuth0 = (options) => {
61
61
  algorithms: ['RS256'],
62
62
  audience: options.audience,
63
63
  issuer: `https://${options.domain}/`,
64
- ...(options.jwtVerifyOptions || {}),
64
+ ...options.jwtVerifyOptions,
65
65
  });
66
66
  return decoded;
67
67
  }
@@ -77,10 +77,8 @@ const useAuth0 = (options) => {
77
77
  [contextField]: decodedPayload,
78
78
  });
79
79
  }
80
- else {
81
- if (options.preventUnauthenticatedAccess) {
82
- throw new UnauthenticatedError(`Unauthenticated!`);
83
- }
80
+ else if (options.preventUnauthenticatedAccess) {
81
+ throw new UnauthenticatedError(`Unauthenticated!`);
84
82
  }
85
83
  }
86
84
  catch (e) {
@@ -94,5 +92,3 @@ const useAuth0 = (options) => {
94
92
  },
95
93
  };
96
94
  };
97
-
98
- export { UnauthenticatedError, useAuth0 };
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@envelop/auth0",
3
- "version": "4.0.0-alpha-d0d0776.0",
3
+ "version": "4.0.0-alpha-ccec0fc.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@envelop/core": "3.0.0-alpha-d0d0776.0",
7
- "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
6
+ "@envelop/core": "3.0.0-alpha-ccec0fc.0",
7
+ "@graphql-tools/graphql": "0.1.0-alpha-e7752ba5.0"
8
8
  },
9
9
  "dependencies": {
10
10
  "jsonwebtoken": "^8.5.1",
@@ -17,33 +17,42 @@
17
17
  },
18
18
  "author": "Dotan Simha <dotansimha@gmail.com>",
19
19
  "license": "MIT",
20
- "main": "index.js",
21
- "module": "index.mjs",
22
- "typings": "index.d.ts",
20
+ "main": "cjs/index.js",
21
+ "module": "esm/index.js",
22
+ "typings": "typings/index.d.ts",
23
23
  "typescript": {
24
- "definition": "index.d.ts"
24
+ "definition": "typings/index.d.ts"
25
25
  },
26
+ "type": "module",
26
27
  "exports": {
27
28
  ".": {
28
29
  "require": {
29
- "default": "./index.js",
30
- "types": "./index.d.ts"
30
+ "types": "./typings/index.d.ts",
31
+ "default": "./cjs/index.js"
31
32
  },
32
33
  "import": {
33
- "default": "./index.mjs",
34
- "types": "./index.d.ts"
34
+ "types": "./typings/index.d.ts",
35
+ "default": "./esm/index.js"
36
+ },
37
+ "default": {
38
+ "types": "./typings/index.d.ts",
39
+ "default": "./esm/index.js"
35
40
  }
36
41
  },
37
42
  "./*": {
38
43
  "require": {
39
- "default": "./*.js",
40
- "types": "./*.d.ts"
44
+ "types": "./typings/*.d.ts",
45
+ "default": "./cjs/*.js"
41
46
  },
42
47
  "import": {
43
- "default": "./*.mjs",
44
- "types": "./*.d.ts"
48
+ "types": "./typings/*.d.ts",
49
+ "default": "./esm/*.js"
50
+ },
51
+ "default": {
52
+ "types": "./typings/*.d.ts",
53
+ "default": "./esm/*.js"
45
54
  }
46
55
  },
47
56
  "./package.json": "./package.json"
48
57
  }
49
- }
58
+ }
@@ -1,7 +1,7 @@
1
1
  import { Plugin } from '@envelop/core';
2
2
  import * as JwksRsa from 'jwks-rsa';
3
3
  import { VerifyOptions, DecodeOptions } from 'jsonwebtoken';
4
- import { GraphQLError } from 'graphql';
4
+ import { GraphQLError } from '@graphql-tools/graphql';
5
5
  export declare type Auth0PluginOptions = {
6
6
  domain: string;
7
7
  audience: string;