Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@advanced-rest-client/oauth-authorization

Package Overview
Dependencies
Maintainers
4
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@advanced-rest-client/oauth-authorization - npm Package Compare versions

Comparing version 5.0.4 to 5.0.5

24

package.json
{
"name": "@advanced-rest-client/oauth-authorization",
"description": "A set of elements that perform oauth authorization",
"version": "5.0.4",
"version": "5.0.5",
"license": "Apache-2.0",

@@ -29,4 +29,4 @@ "main": "index.js",

"dependencies": {
"@advanced-rest-client/arc-events": "^0.2.13",
"@advanced-rest-client/arc-types": "^0.2.47",
"@advanced-rest-client/arc-events": "^0.2.14",
"@advanced-rest-client/arc-types": "^0.2.49",
"@advanced-rest-client/events-target-mixin": "^3.2.3",

@@ -43,16 +43,16 @@ "@advanced-rest-client/headers-parser-mixin": "^3.2.0",

"@advanced-rest-client/arc-demo-helper": "^2.2.5",
"@esm-bundle/chai": "^4.1.5",
"@esm-bundle/chai": "^4.3.0",
"@open-wc/eslint-config": "^4.2.0",
"@open-wc/testing": "^2.5.32",
"@web/dev-server": "^0.1.5",
"@web/test-runner": "^0.12.5",
"@web/test-runner-playwright": "^0.8.0",
"@web/dev-server": "^0.1.7",
"@web/test-runner": "^0.12.15",
"@web/test-runner-playwright": "^0.8.4",
"cryptojslib": "^3.1.2",
"eslint": "^7.18.0",
"eslint": "^7.19.0",
"eslint-config-prettier": "^7.2.0",
"husky": "^4.3.8",
"jsrsasign": "^10.1.5",
"lint-staged": "^10.5.3",
"sinon": "^9.2.3",
"typescript": "^4.1.3",
"jsrsasign": "^10.1.8",
"lint-staged": "^10.5.4",
"sinon": "^9.2.4",
"typescript": "^4.1.4",
"typescript-lit-html-plugin": "^0.9.0"

@@ -59,0 +59,0 @@ },

@@ -50,5 +50,5 @@ /** @typedef {import('@advanced-rest-client/arc-types').Authorization.OAuth2AuthorizationRequestCustomData} OAuth2AuthorizationRequestCustomData */

*
* @param {object} headers A regular JS map with headers definition
* @param {Record<string, string>} headers A regular JS map with headers definition
* @param {OAuth2CustomData} data Value of settings' `customData` property
* @returns {object} The copy of the headers object, if it was altered. Otherwise the same object.
* @returns {Record<string, string>} The copy of the headers object, if it was altered. Otherwise the same object.
*/

@@ -64,2 +64,2 @@ export function applyCustomSettingsHeaders(headers, data) {

return copy;
}
}

@@ -281,2 +281,11 @@ import { Authorization } from '@advanced-rest-client/arc-types';

/**
* Builds the authorization header for Client Credentials grant type.
* According to the spec the authorization header for this grant type
* is the Base64 of `clientId` + `:` + `clientSecret`.
*
* @param settings The OAuth 2 settings to use
*/
getClientCredentialsHeader(settings: Authorization.OAuth2Authorization): string;
/**
* Requests a token for `client_credentials` request type.

@@ -313,2 +322,2 @@ *

getCustomGrantBody(): string;
}
}

@@ -617,12 +617,13 @@ /* eslint-disable no-param-reassign */

*
* @param {String} url Base URI of the endpoint. Custom properties will be applied to the final URL.
* @param {String} body Generated body for given type. Custom properties will be applied to the final body.
* @param {string} url Base URI of the endpoint. Custom properties will be applied to the final URL.
* @param {string} body Generated body for given type. Custom properties will be applied to the final body.
* @param {Record<string, string>=} optHeaders Optional headers to add to the request. Applied after custom data.
* @return {Promise<TokenInfo>} Promise resolved to the response string.
*/
async requestToken(url, body) {
async requestToken(url, body, optHeaders) {
const urlInstance = new URL(url);
const { settings } = this;
let headers = {
let headers = /** @type Record<string, string> */ ({
'content-type': 'application/x-www-form-urlencoded',
};
});
if (settings.customData) {

@@ -635,2 +636,5 @@ if (settings.customData.token) {

}
if (optHeaders) {
headers = { ...headers, ...optHeaders };
}
const init = /** @type RequestInit */ ({

@@ -682,3 +686,3 @@ headers,

}
tokenInfo[name] = info[name];
tokenInfo[name] = info[key];
});

@@ -697,3 +701,3 @@ } else {

if (tokenInfo.error) {
throw new CodeError(tokenInfo.error, tokenInfo.errorDescription);
throw new CodeError(tokenInfo.errorDescription, tokenInfo.error);
}

@@ -718,3 +722,3 @@ const expiresIn = Number(tokenInfo.expiresIn);

if (e instanceof CodeError) {
this[reportOAuthError](...this[createErrorParams](e.message, e.code));
this[reportOAuthError](...this[createErrorParams](e.code, e.message));
} else {

@@ -734,6 +738,13 @@ this[reportOAuthError](`Couldn't connect to the server. ${e.message}`, 'request_error');

const { settings } = this;
const url = settings.accessTokenUri;
const { accessTokenUri, deliveryMethod='body', deliveryName='authorization' } = settings;
const body = this.getClientCredentialsBody();
let headers = /** @type Record<string, string> */ (null);
const headerTransport = deliveryMethod === 'header';
if (headerTransport) {
headers = {
[deliveryName]: this.getClientCredentialsHeader(settings),
};
}
try {
const tokenInfo = await this.requestToken(url, body);
const tokenInfo = await this.requestToken(accessTokenUri, body, headers);
this[handleTokenInfo](tokenInfo);

@@ -752,8 +763,9 @@ } catch (cause) {

const { settings } = this;
const headerTransport = settings.deliveryMethod === 'header';
const params = new URLSearchParams();
params.set('grant_type', 'client_credentials');
if (settings.clientId) {
if (!headerTransport && settings.clientId) {
params.set('client_id', settings.clientId);
}
if (settings.clientSecret) {
if (!headerTransport && settings.clientSecret) {
params.set('client_secret', settings.clientSecret);

@@ -768,2 +780,16 @@ }

/**
* Builds the authorization header for Client Credentials grant type.
* According to the spec the authorization header for this grant type
* is the Base64 of `clientId` + `:` + `clientSecret`.
*
* @param {OAuth2Settings} settings The OAuth 2 settings to use
* @returns {string}
*/
getClientCredentialsHeader(settings) {
const { clientId='', clientSecret='' } = settings;
const hash = btoa(`${clientId}:${clientSecret}`);
return `Basic ${hash}`;
}
/**
* Requests a token for `client_credentials` request type.

@@ -770,0 +796,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