Socket
Socket
Sign inDemoInstall

@auth0-kits/server

Package Overview
Dependencies
Maintainers
2
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@auth0-kits/server - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

5

package.json
{
"name": "@auth0-kits/server",
"version": "1.0.1",
"version": "1.1.0",
"description": "",

@@ -13,4 +13,5 @@ "main": "index.js",

"node-fetch": "^2.6.0",
"querystring": "^0.2.0"
"querystring": "^0.2.0",
"untracer": "^1.0.0"
}
}

158

src/auth0.service.js
const querystring = require('querystring');
const fetch = require('node-fetch');
const Tracer = require('untracer');

@@ -9,3 +10,25 @@ const TOKEN_URL = '/oauth/token';

class Auth0Service {
constructor({ auth0TenantUrl, oauthRedirectUri, clientId, clientSecret }) {
/**
*Creates an instance of Auth0Service.
* @param {*} {
* auth0TenantUrl,
* oauthRedirectUri,
* clientId,
* clientSecret,
* debug = false,
* tracer,
* log,
* } options
* @param {Tracer?} options.tracer
* @memberof Auth0Service
*/
constructor({
auth0TenantUrl,
oauthRedirectUri,
clientId,
clientSecret,
debug = false,
tracer,
log,
}) {
this.auth0TenantUrl = auth0TenantUrl;

@@ -15,2 +38,4 @@ this.clientId = clientId;

this.oauthRedirectUri = oauthRedirectUri;
this.tracer = tracer || new Tracer({ log, silent: !debug });
}

@@ -27,4 +52,7 @@

async getManagementApiToken({ clientId, clientSecret } = {}) {
this.tracer.trace('getManagementApiToken');
const client_id = clientId || this.clientId;
const client_secret = clientSecret || this.clientSecret;
this.tracer.crumb({ client_id, client_secret });

@@ -37,11 +65,31 @@ const body = querystring.stringify({

});
this.tracer.crumb({ body });
const response = await fetch(`${this.auth0TenantUrl}${TOKEN_URL}`, {
method: 'POST',
body,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
});
const resToken = await response.json();
let response;
try {
const managementTokenUrl = `${this.auth0TenantUrl}${TOKEN_URL}`;
this.tracer.crumb({ managementTokenUrl });
return (!resToken || !resToken.access_token) ? null : resToken.access_token;
response = await fetch(managementTokenUrl, {
method: 'POST',
body,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
});
const { headers, status, statusText } = response;
this.tracer.crumb({ headers, status, statusText });
} catch (error) {
throw this.tracer.break(error);
}
let tokenResponse;
try {
tokenResponse = await response.json();
this.tracer.crumb({ tokenResponse });
} catch (error) {
throw this.tracer.break(error);
}
const result = (!resToken || !resToken.access_token) ? null : resToken.access_token;
return this.tracer.dump(result);
}

@@ -57,10 +105,32 @@

async getUserInfo(userId) {
const managementToken = await this.getManagementApiToken();
this.tracer.trace('getUserInfo', { userId });
let managementToken;
try {
managementToken = await this.getManagementApiToken({ logBreadcrumbs });
this.tracer.crumb({ managementToken });
if (!managementToken) {
throw new Error('Cannot get user info because managementToken is null.');
}
} catch (error) {
throw this.tracer.break(error);
}
const url = `${this.auth0TenantUrl}${USER_URL}${userId}`;
const response = await fetch(url, {
headers: {
'Authorization': `Bearer ${managementToken}`,
},
});
return response.json();
this.tracer.crumb({ url });
let response;
try {
response = await fetch(url, {
headers: { 'Authorization': `Bearer ${managementToken}` },
});
const { headers, status, statusText } = response;
this.tracer.crumb({ headers, status, statusText });
} catch (error) {
throw this.tracer.break(error);
}
const responseJson = await response.json();
return this.tracer.dump(responseJson);
}

@@ -76,2 +146,4 @@

async getUserAccessTokenByCode(authorizationCode) {
this.tracer.trace('getUserAccessTokenByCode', { authorizationCode });
const body = querystring.stringify({

@@ -84,8 +156,23 @@ grant_type: 'authorization_code',

});
const response = await fetch(`${this.auth0TenantUrl}${TOKEN_URL}`, {
method: 'POST',
body,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
});
return response.json();
this.tracer.crumb({ body });
let response;
try {
const url = `${this.auth0TenantUrl}${TOKEN_URL}`;
this.tracer.crumb({ url });
response = await fetch(url, {
method: 'POST',
body,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
});
const { headers, status, statusText } = response;
this.tracer.crumb({ headers, status, statusText });
} catch (error) {
throw this.tracer.break(error);
}
const responseJson = await response.json();
return this.tracer.dump(responseJson);
}

@@ -101,2 +188,4 @@

async renewToken(refreshToken) {
this.tracer.trace('renewToken', { refreshToken });
const body = querystring.stringify({

@@ -109,8 +198,23 @@ grant_type: 'refresh_token',

});
const response = await fetch(`${this.auth0TenantUrl}${TOKEN_URL}`, {
method: 'POST',
body,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
});
return response.json();
this.tracer.crumb({ body });
let response;
try {
const url = `${this.auth0TenantUrl}${TOKEN_URL}`;
this.tracer.crumb({ url });
response = await fetch(url, {
method: 'POST',
body,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
});
const { headers, status, statusText } = response;
this.tracer.crumb({ headers, status, statusText });
} catch (error) {
throw this.tracer.break(error);
}
const responseJson = await response.json();
return this.tracer.dump(responseJson);
}

@@ -117,0 +221,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc