@hapi/bell 12.2.0 → 13.0.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/LICENSE.md CHANGED
@@ -1,4 +1,5 @@
1
- Copyright (c) 2014-2020, Sideway Inc, and project contributors
1
+ Copyright (c) 2014-2022, Project contributors
2
+ Copyright (c) 2014-2020, Sideway Inc
2
3
  Copyright (c) 2014, Walmart.
3
4
  All rights reserved.
4
5
 
package/lib/index.js CHANGED
@@ -9,7 +9,7 @@ const Providers = require('./providers');
9
9
 
10
10
  const internals = {
11
11
  simulate: false,
12
- flexBoolean: Joi.boolean().truthy('true', 'yes', 1, '1').falsy('false', 'no', 0, '0')
12
+ flexBoolean: Joi.boolean().truthy('yes', 1, '1').falsy('no', 0, '0')
13
13
  };
14
14
 
15
15
 
@@ -25,10 +25,9 @@ exports.oauth = OAuth;
25
25
  exports.plugin = {
26
26
  pkg: require('../package.json'),
27
27
  requirements: {
28
- hapi: '>=19.0.0'
28
+ hapi: '>=20.0.0'
29
29
  },
30
-
31
- register: function (server, options) {
30
+ register: function (server) {
32
31
 
33
32
  server.auth.scheme('bell', internals.implementation);
34
33
  server.expose('oauth', OAuth);
@@ -128,7 +127,7 @@ internals.implementation = function (server, options) {
128
127
  // Lookup provider
129
128
 
130
129
  if (typeof settings.provider === 'object') {
131
- settings.name = settings.provider.name || 'custom';
130
+ settings.name = settings.provider.name ?? 'custom';
132
131
  }
133
132
  else {
134
133
  settings.name = settings.provider;
@@ -157,7 +156,7 @@ internals.implementation = function (server, options) {
157
156
  clearInvalid: true
158
157
  };
159
158
 
160
- settings.cookie = settings.cookie || 'bell-' + settings.name;
159
+ settings.cookie = settings.cookie ?? `bell-${settings.name}`;
161
160
  server.state(settings.cookie, cookieOptions);
162
161
 
163
162
  if (internals.simulate) {
package/lib/oauth.js CHANGED
@@ -196,13 +196,13 @@ exports.v2 = function (settings) {
196
196
  }
197
197
  }
198
198
 
199
- let scope = settings.scope || settings.provider.scope;
199
+ let scope = settings.scope ?? settings.provider.scope;
200
200
  if (typeof scope === 'function') {
201
201
  scope = scope(request);
202
202
  }
203
203
 
204
204
  if (scope) {
205
- query.scope = scope.join(settings.provider.scopeSeparator || ' ');
205
+ query.scope = scope.join(settings.provider.scopeSeparator ?? ' ');
206
206
  }
207
207
 
208
208
  const state = {
@@ -243,7 +243,7 @@ exports.v2 = function (settings) {
243
243
  credentials.query = state.query;
244
244
  h.unstate(cookie);
245
245
 
246
- const requestState = request.query.state || '';
246
+ const requestState = request.query.state ?? '';
247
247
  if (state.nonce !== requestState.substr(0, Math.min(requestState.length, internals.nonceLength))) {
248
248
  return h.unauthenticated(Boom.internal('Incorrect ' + name + ' state parameter'), { credentials });
249
249
  }
@@ -393,9 +393,11 @@ exports.Client = internals.Client = function (options) {
393
393
  temporary: internals.Client.baseUri(options.provider.temporary),
394
394
  token: internals.Client.baseUri(options.provider.token),
395
395
  clientId: options.clientId,
396
- clientSecret: options.provider.signatureMethod === 'RSA-SHA1' ? options.clientSecret : internals.encode(options.clientSecret || '') + '&',
396
+ clientSecret: options.provider.signatureMethod === 'RSA-SHA1' ? options.clientSecret : internals.encode(options.clientSecret ?? '') + '&',
397
397
  signatureMethod: options.provider.signatureMethod
398
398
  };
399
+
400
+ this._wreckOptions = { ...options.wreck };
399
401
  };
400
402
 
401
403
 
@@ -451,6 +453,7 @@ internals.Client.prototype._request = async function (method, uri, params, oauth
451
453
  // Calculate OAuth header
452
454
 
453
455
  const requestOptions = {
456
+ ...this._wreckOptions,
454
457
  headers: {
455
458
  Authorization: internals.Client.header(oauth)
456
459
  }
@@ -471,7 +474,7 @@ internals.Client.prototype._request = async function (method, uri, params, oauth
471
474
  return Wreck.request(method, uri, requestOptions);
472
475
  }
473
476
 
474
- const desc = (options.desc || 'resource');
477
+ const desc = (options.desc ?? 'resource');
475
478
  try {
476
479
  const { res, payload } = await Wreck[method](uri, requestOptions);
477
480
  var result = { payload: payload.toString(), statusCode: res.statusCode };
@@ -5,23 +5,22 @@ const internals = {};
5
5
 
6
6
  exports = module.exports = function (options) {
7
7
 
8
- options = options || {};
9
- const tenantId = options.tenant || 'common';
8
+ const tenantId = options?.tenant ?? 'common';
10
9
 
11
10
  return {
12
11
  protocol: 'oauth2',
13
12
  useParamsAuth: true,
14
- auth: 'https://login.microsoftonline.com/' + tenantId + '/oauth2/authorize',
15
- token: 'https://login.microsoftonline.com/' + tenantId + '/oauth2/token',
13
+ auth: `https://login.microsoftonline.com/${tenantId}/oauth2/authorize`,
14
+ token: `https://login.microsoftonline.com/${tenantId}/oauth2/token`,
16
15
  scope: ['openid', 'offline_access', 'profile'],
17
16
  profile: async function (credentials, params, get) {
18
17
 
19
- const profile = await get('https://login.microsoftonline.com/' + tenantId + '/openid/userinfo');
18
+ const profile = await get(`https://login.microsoftonline.com/${tenantId}/openid/userinfo`);
20
19
 
21
20
  credentials.profile = {
22
21
  id: profile.oid,
23
22
  displayName: profile.name,
24
- email: profile.upn || profile.email,
23
+ email: profile.upn ?? profile.email,
25
24
  raw: profile
26
25
  };
27
26
  }
@@ -7,14 +7,13 @@ const internals = {};
7
7
 
8
8
  exports = module.exports = function (options) {
9
9
 
10
- options = options || {};
11
- const tenantId = options.tenant || 'common';
10
+ const tenantId = options?.tenant ?? 'common';
12
11
 
13
12
  return {
14
13
  protocol: 'oauth2',
15
14
  useParamsAuth: true,
16
- auth: 'https://login.microsoftonline.com/' + tenantId + '/oauth2/v2.0/authorize',
17
- token: 'https://login.microsoftonline.com/' + tenantId + '/oauth2/v2.0/token',
15
+ auth: `https://login.microsoftonline.com/${tenantId}/oauth2/v2.0/authorize`,
16
+ token: `https://login.microsoftonline.com/${tenantId}/oauth2/v2.0/token`,
18
17
  scope: [
19
18
  'openid',
20
19
  'offline_access', // Enable app to get refresh_tokens
@@ -30,7 +29,7 @@ exports = module.exports = function (options) {
30
29
  credentials.profile = {
31
30
  id: profile.id,
32
31
  displayName: profile.displayName,
33
- email: profile.userPrincipalName || profile.mail,
32
+ email: profile.userPrincipalName ?? profile.mail,
34
33
  raw: profile
35
34
  };
36
35
  }
@@ -17,14 +17,14 @@ exports = module.exports = function (options) {
17
17
 
18
18
  return {
19
19
  protocol: 'oauth2',
20
- auth: settings.uri + '/oauth2/authorize',
21
- token: settings.uri + '/oauth2/token',
20
+ auth: `${settings.uri}/oauth2/authorize`,
21
+ token: `${settings.uri}/oauth2/token`,
22
22
  scope: ['openid', 'email', 'profile'],
23
23
  scopeSeparator: ' ',
24
24
  useParamsAuth: true,
25
25
  profile: async function (credentials, params, get) {
26
26
 
27
- const profile = await get(settings.uri + '/oauth2/userInfo');
27
+ const profile = await get(`${settings.uri}/oauth2/userInfo`);
28
28
 
29
29
  credentials.profile = {
30
30
  id: profile.sub,
@@ -11,8 +11,8 @@ exports = module.exports = function () {
11
11
  return {
12
12
  protocol: 'oauth2',
13
13
  useParamsAuth: true,
14
- auth: digitalOceanUrl + '/authorize',
15
- token: digitalOceanUrl + '/token',
14
+ auth: `${digitalOceanUrl}/authorize`,
15
+ token: `${digitalOceanUrl}/token`,
16
16
  profile: async function (credentials, params, get) {
17
17
 
18
18
  const profile = await get(digitalOceanUserUrl);
@@ -7,12 +7,12 @@ exports = module.exports = function () {
7
7
 
8
8
  return {
9
9
  protocol: 'oauth2',
10
- auth: 'https://discordapp.com/api/oauth2/authorize',
11
- token: 'https://discordapp.com/api/oauth2/token',
12
- scope: ['email', 'identify'], // https://discordapp.com/developers/docs/topics/oauth2#scopes
10
+ auth: 'https://discord.com/api/oauth2/authorize',
11
+ token: 'https://discord.com/api/oauth2/token',
12
+ scope: ['email', 'identify'], // https://discord.com/developers/docs/topics/oauth2#scopes
13
13
  profile: async function (credentials, params, get) {
14
14
 
15
- const profile = await get('https://discordapp.com/api/users/@me');
15
+ const profile = await get('https://discord.com/api/users/@me');
16
16
 
17
17
  credentials.profile = {
18
18
  id: profile.id,
@@ -23,7 +23,7 @@ exports = module.exports = function () {
23
23
  verified: profile.verified,
24
24
  avatar: {
25
25
  id: profile.avatar,
26
- url: 'https://cdn.discordapp.com/avatars/' + profile.id + '/' + profile.avatar + '.png'
26
+ url: `https://cdn.discordapp.com/avatars/${profile.id}/${profile.avatar}.png`
27
27
  },
28
28
  raw: profile
29
29
  };
@@ -14,7 +14,7 @@ exports = module.exports = function (options) {
14
14
  fields: 'id,name,email,first_name,last_name,middle_name,picture,gender,link,locale,timezone,updated_time,verified',
15
15
  scope: ['email']
16
16
  };
17
- const settings = Hoek.applyToDefaults(defaults, options || {});
17
+ const settings = Hoek.applyToDefaults(defaults, options ?? {});
18
18
 
19
19
  return {
20
20
  protocol: 'oauth2',
@@ -22,7 +22,7 @@ exports = module.exports = function (options) {
22
22
 
23
23
  credentials.profile = {
24
24
  id: profile.id,
25
- displayName: profile.firstName + ' ' + profile.lastName,
25
+ displayName: `${profile.firstName} ${profile.lastName}`,
26
26
  name: {
27
27
  first: profile.firstName,
28
28
  last: profile.lastName
@@ -5,16 +5,14 @@ const internals = {};
5
5
 
6
6
  exports = module.exports = function (options) {
7
7
 
8
- options = options || {};
9
-
10
- const uri = options.uri || 'https://github.com';
11
- const user = options.uri ? options.uri + '/api/v3/user' : 'https://api.github.com/user';
8
+ const uri = options?.uri ?? 'https://github.com';
9
+ const user = options?.uri ? `${options.uri}/api/v3/user` : 'https://api.github.com/user';
12
10
 
13
11
  return {
14
12
  protocol: 'oauth2',
15
13
  useParamsAuth: true,
16
- auth: uri + '/login/oauth/authorize',
17
- token: uri + '/login/oauth/access_token',
14
+ auth: `${uri}/login/oauth/authorize`,
15
+ token: `${uri}/login/oauth/access_token`,
18
16
  scope: ['user:email'],
19
17
  scopeSeparator: ',',
20
18
  headers: {
@@ -5,15 +5,13 @@ const internals = {};
5
5
 
6
6
  exports = module.exports = function (options) {
7
7
 
8
- options = options || {};
9
-
10
- const uri = options.uri || 'https://gitlab.com';
11
- const user = uri + '/api/v3/user';
8
+ const uri = options?.uri ?? 'https://gitlab.com';
9
+ const user = `${uri}/api/v3/user`;
12
10
 
13
11
  return {
14
12
  protocol: 'oauth2',
15
- auth: uri + '/oauth/authorize',
16
- token: uri + '/oauth/token',
13
+ auth: `${uri}/oauth/authorize`,
14
+ token: `${uri}/oauth/token`,
17
15
  profile: async function (credentials, params, get) {
18
16
 
19
17
  const profile = await get(user);
@@ -5,8 +5,6 @@ const internals = {};
5
5
 
6
6
  exports = module.exports = function (options) {
7
7
 
8
- options = options || {};
9
-
10
8
  return {
11
9
  protocol: 'oauth2',
12
10
  useParamsAuth: true,
@@ -23,7 +21,7 @@ exports = module.exports = function (options) {
23
21
  raw: params.user
24
22
  };
25
23
 
26
- if (options.extendedProfile === false) { // Defaults to true
24
+ if (options?.extendedProfile === false) { // Defaults to true
27
25
  return;
28
26
  }
29
27
 
@@ -15,11 +15,11 @@ exports = module.exports = function (options) {
15
15
  profile: async function (credentials, params, get) {
16
16
 
17
17
  let fields = '';
18
- if (this.providerParams && this.providerParams.fields) {
19
- fields = '?projection=' + this.providerParams.fields;
18
+ if (this.providerParams?.fields) {
19
+ fields = `?projection=${this.providerParams.fields}`;
20
20
  }
21
21
 
22
- const profile = await get('https://api.linkedin.com/v2/me' + fields);
22
+ const profile = await get(`https://api.linkedin.com/v2/me${fields}`);
23
23
  const email = await get('https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))');
24
24
 
25
25
  credentials.profile = {
@@ -23,7 +23,7 @@ exports = module.exports = function (options) {
23
23
  first: profile.first_name,
24
24
  last: profile.last_name
25
25
  },
26
- email: profile.emails && (profile.emails.preferred || profile.emails.account),
26
+ email: profile.emails?.preferred ?? profile.emails?.account,
27
27
  raw: profile
28
28
  };
29
29
  }
@@ -15,16 +15,16 @@ exports = module.exports = function (options) {
15
15
 
16
16
  const settings = Joi.attempt(options, internals.schema);
17
17
 
18
- let baseUri = settings.uri + '/oauth2';
18
+ let baseUri = `${settings.uri}/oauth2`;
19
19
  if (settings.authorizationServerId) {
20
- baseUri += '/' + settings.authorizationServerId;
20
+ baseUri += `/${settings.authorizationServerId}`;
21
21
  }
22
22
 
23
23
  return {
24
24
  protocol: 'oauth2',
25
25
  useParamsAuth: true,
26
- auth: baseUri + '/v1/authorize',
27
- token: baseUri + '/v1/token',
26
+ auth: `${baseUri}/v1/authorize`,
27
+ token: `${baseUri}/v1/token`,
28
28
  scope: ['profile', 'openid', 'email', 'offline_access'],
29
29
  profile: async function (credentials, params, get) {
30
30
 
@@ -17,8 +17,8 @@ exports = module.exports = function (options) {
17
17
  return {
18
18
  protocol: 'oauth2',
19
19
  useParamsAuth: true,
20
- auth: settings.uri + '/oauthserver/auth/',
21
- token: settings.uri + '/oauthserver/token/',
20
+ auth: `${settings.uri}/oauthserver/auth/`,
21
+ token: `${settings.uri}/oauthserver/token/`,
22
22
  scope: ['whoami'],
23
23
  scopeSeparator: ',',
24
24
  profile: async function (credentials, params, get) {
@@ -27,7 +27,7 @@ exports = module.exports = function (options) {
27
27
  access_token: credentials.token
28
28
  };
29
29
 
30
- const profile = await get(settings.uri + '/api/user.whoami', query);
30
+ const profile = await get(`${settings.uri}/api/user.whoami`, query);
31
31
 
32
32
  credentials.profile = {
33
33
  id: profile.result.phid,
@@ -5,20 +5,18 @@ const internals = {};
5
5
 
6
6
  exports = module.exports = function (options) {
7
7
 
8
- options = options || {};
9
-
10
- const uri = options.uri || 'https://login-dev.ext.hpe.com';
8
+ const uri = options?.uri ?? 'https://login-dev.ext.hpe.com';
11
9
 
12
10
  return {
13
11
  protocol: 'oauth2',
14
- auth: uri + '/as/authorization.oauth2',
15
- token: uri + '/as/token.oauth2',
12
+ auth: `${uri}/as/authorization.oauth2`,
13
+ token: `${uri}/as/token.oauth2`,
16
14
  scope: ['openid', 'email'],
17
15
  scopeSeparator: ' ',
18
16
  useParamsAuth: true,
19
17
  profile: async function (credentials, params, get) {
20
18
 
21
- const profile = await get(uri + '/idp/userinfo.openid');
19
+ const profile = await get(`${uri}/idp/userinfo.openid`);
22
20
 
23
21
  credentials.profile = {
24
22
  id: profile.sub,
@@ -23,13 +23,13 @@ internals.defaults = {
23
23
 
24
24
  exports = module.exports = function (options) {
25
25
 
26
- const combinedSettings = Hoek.applyToDefaults(internals.defaults, options || {});
26
+ const combinedSettings = Hoek.applyToDefaults(internals.defaults, options ?? {});
27
27
  const settings = Joi.attempt(combinedSettings, internals.schema);
28
28
 
29
29
  return {
30
30
  protocol: 'oauth2',
31
- auth: settings.uri + '/services/oauth2/authorize',
32
- token: settings.uri + '/services/oauth2/token',
31
+ auth: `${settings.uri}/services/oauth2/authorize`,
32
+ token: `${settings.uri}/services/oauth2/token`,
33
33
  useParamsAuth: true,
34
34
  profile: async function (credentials, params, get) {
35
35
 
@@ -5,16 +5,14 @@ const internals = {};
5
5
 
6
6
  exports = module.exports = function (options) {
7
7
 
8
- options = options || {};
9
-
10
- const uri = options.uri || 'https://accounts.spotify.com';
11
- const user = options.uri ? options.uri + '/v1/me' : 'https://api.spotify.com/v1/me';
8
+ const uri = options?.uri ?? 'https://accounts.spotify.com';
9
+ const user = options?.uri ? `${options.uri}/v1/me` : 'https://api.spotify.com/v1/me';
12
10
 
13
11
  return {
14
12
  protocol: 'oauth2',
15
13
  useParamsAuth: true,
16
- auth: uri + '/authorize',
17
- token: uri + '/api/token',
14
+ auth: `${uri}/authorize`,
15
+ token: `${uri}/api/token`,
18
16
  scope: ['user-read-email'],
19
17
  scopeSeparator: ',',
20
18
  headers: { 'User-Agent': 'hapi-bell-spotify' },
@@ -8,16 +8,15 @@ const internals = {};
8
8
 
9
9
  exports = module.exports = function (options) {
10
10
 
11
- options = options || {};
12
- Hoek.assert(options.apiKey, 'The property "apiKey" is required for the trakt.tv bell provider');
11
+ Hoek.assert(options?.apiKey, 'The property "apiKey" is required for the trakt.tv bell provider');
13
12
 
14
13
  const uri = 'https://api.trakt.tv';
15
- const user = uri + '/users/me';
14
+ const user = `${uri}/users/me`;
16
15
 
17
16
  return {
18
17
  protocol: 'oauth2',
19
- auth: uri + '/oauth/authorize',
20
- token: uri + '/oauth/token',
18
+ auth: `${uri}/oauth/authorize`,
19
+ token: `${uri}/oauth/token`,
21
20
  headers: {
22
21
  'trakt-api-version': 2,
23
22
  'trakt-api-key': options.apiKey
@@ -13,7 +13,7 @@ const internals = {
13
13
 
14
14
  exports = module.exports = function (options) {
15
15
 
16
- const settings = Hoek.applyToDefaults(internals.defaults, options || {});
16
+ const settings = Hoek.applyToDefaults(internals.defaults, options ?? {});
17
17
 
18
18
  return {
19
19
  protocol: 'oauth',
@@ -36,7 +36,7 @@ exports = module.exports = function (options) {
36
36
  user_id: params.user_id
37
37
  };
38
38
 
39
- const getParams = Hoek.applyToDefaults(paramDefaults, settings.getParams || {});
39
+ const getParams = Hoek.applyToDefaults(paramDefaults, settings.getParams ?? {});
40
40
 
41
41
  const profile = await get(`https://api.twitter.com/1.1/${settings.getMethod}.json`, getParams);
42
42
  credentials.profile.displayName = profile.name;
@@ -5,8 +5,8 @@ const internals = {};
5
5
 
6
6
  exports = module.exports = function (options) {
7
7
 
8
- options = options || {};
9
- const version = options.version || '5.73';
8
+ options = options ?? {};
9
+ const version = options.version ?? '5.73';
10
10
  const key_id = parseInt(version) < 5 ? 'uid' : 'id';
11
11
 
12
12
  return {
@@ -13,11 +13,11 @@ exports = module.exports = function (options) {
13
13
  token: 'https://api.login.yahoo.com/oauth/v2/get_token',
14
14
  profile: async function (credentials, params, get) {
15
15
 
16
- const profile = await get('https://social.yahooapis.com/v1/user/' + params.xoauth_yahoo_guid + '/profile', { format: 'json' });
16
+ const profile = await get(`https://social.yahooapis.com/v1/user/${params.xoauth_yahoo_guid}/profile`, { format: 'json' });
17
17
 
18
18
  credentials.profile = {
19
19
  id: profile.profile.guid,
20
- displayName: profile.profile.givenName + ' ' + profile.profile.familyName,
20
+ displayName: `${profile.profile.givenName} ${profile.profile.familyName}`,
21
21
  name: {
22
22
  first: profile.profile.givenName,
23
23
  last: profile.profile.familyName
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@hapi/bell",
3
3
  "description": "Third-party login plugin for hapi",
4
- "version": "12.2.0",
4
+ "version": "13.0.0",
5
5
  "repository": "git://github.com/hapijs/bell",
6
6
  "main": "lib/index.js",
7
7
  "engines": {
8
- "node": ">=12.0.0"
8
+ "node": ">=14.0.0"
9
9
  },
10
10
  "files": [
11
11
  "lib"
@@ -43,20 +43,26 @@
43
43
  "wordpress",
44
44
  "yahoo"
45
45
  ],
46
+ "eslintConfig": {
47
+ "extends": [
48
+ "plugin:@hapi/module"
49
+ ]
50
+ },
46
51
  "dependencies": {
47
- "@hapi/boom": "9.x.x",
48
- "@hapi/bounce": "2.x.x",
49
- "@hapi/cryptiles": "^5.1.0",
50
- "@hapi/hoek": "9.x.x",
51
- "@hapi/wreck": "17.x.x",
52
- "joi": "17.x.x"
52
+ "@hapi/boom": "^10.0.0",
53
+ "@hapi/bounce": "^3.0.0",
54
+ "@hapi/cryptiles": "^6.0.0",
55
+ "@hapi/hoek": "^10.0.0",
56
+ "@hapi/wreck": "^18.0.0",
57
+ "joi": "^17.0.0"
53
58
  },
54
59
  "devDependencies": {
55
- "@hapi/code": "8.x.x",
56
- "@hapi/hapi": "20.x.x",
57
- "@hapi/hawk": "8.x.x",
58
- "@hapi/lab": "24.x.x",
59
- "@hapi/teamwork": "5.x.x"
60
+ "@hapi/code": "^9.0.0",
61
+ "@hapi/eslint-plugin": "^6.0.0",
62
+ "@hapi/hapi": "^21.0.0-beta.1",
63
+ "@hapi/hawk": "^8.0.0",
64
+ "@hapi/lab": "^25.0.1",
65
+ "@hapi/teamwork": "^6.0.0"
60
66
  },
61
67
  "scripts": {
62
68
  "test": "lab -a @hapi/code -t 100 -L -m 3000",