Socket
Socket
Sign inDemoInstall

@ambassify/ambassify-client

Package Overview
Dependencies
7
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.1.2 to 3.2.0

test/impersonation.js

4

CHANGELOG.md

@@ -14,4 +14,8 @@ # Changelog

## 3.2.0
## 3.1.2
## 3.1.2
## 3.1.1

@@ -18,0 +22,0 @@

@@ -15,2 +15,6 @@ 'use strict';

var _stringify = require('babel-runtime/core-js/json/stringify');
var _stringify2 = _interopRequireDefault(_stringify);
var _extends2 = require('babel-runtime/helpers/extends');

@@ -47,2 +51,3 @@

var FetchApi = require('@ambassify/fetch-api');
var AmbassifyError = require('@ambassify/error');

@@ -59,2 +64,63 @@ var _require = require('./refresh-token'),

(0, _createClass3.default)(AmbassifyApi, null, [{
key: 'impersonate',
value: function impersonate() {
var guardianConfig = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var _this2 = this;
var tokenOptions = arguments[1];
var clientOptions = arguments[2];
var _guardianConfig$baseU = guardianConfig.baseUrl,
baseUrl = _guardianConfig$baseU === undefined ? '' : _guardianConfig$baseU,
clientId = guardianConfig.clientId,
clientSecret = guardianConfig.clientSecret,
guestToken = guardianConfig.guestToken;
var guardian = new AmbassifyApi({
baseUrl: baseUrl,
tokenType: 'Bearer',
token: guestToken
});
tokenOptions = (0, _extends3.default)({}, tokenOptions, {
grant_type: 'impersonate',
client_id: clientId,
client_secret: clientSecret
});
return guardian.post('/token', tokenOptions).then(function (res) {
if (!res.ok) {
throw AmbassifyError.fromExternal({
message: 'Failed to retrieve token',
response: {
status: res.status,
statusText: res.statusText,
body: res.body,
text: (0, _stringify2.default)(res.body)
}
});
}
var _res$body = res.body,
access_token = _res$body.access_token,
refresh_token = _res$body.refresh_token;
var tokenData = jwt.decode(access_token);
return new _this2((0, _extends3.default)({
tokenType: 'Bearer',
token: access_token,
refreshToken: refresh_token,
clientId: clientId,
clientSecret: clientSecret,
tokenEndpoint: baseUrl.replace(/\/*$/, '') + '/token',
organization: tokenData && tokenData.oid
}, clientOptions));
});
}
}, {
key: 'addAuthenticationOptions',

@@ -133,6 +199,6 @@ value: function addAuthenticationOptions(options) {

value: function refreshToken() {
var _this2 = this;
var _this3 = this;
return doRefreshToken(this.fetch, this.options).then(function (res) {
return _this2._updateAuthentication(res);
return _this3._updateAuthentication(res);
});

@@ -155,3 +221,3 @@ }

value: function _request(url, options) {
var _this3 = this;
var _this4 = this;

@@ -173,7 +239,7 @@ if (!this.refreshTokenEnabled()) return (0, _get4.default)(AmbassifyApi.prototype.__proto__ || (0, _getPrototypeOf2.default)(AmbassifyApi.prototype), '_request', this).call(this, url, options);

return doCachedRefreshToken(this.fetch, (0, _extends3.default)({}, this.options, { token: token })).then(function (res) {
_this3._updateAuthentication(res);
_this4._updateAuthentication(res);
_set(options, 'headers.authorization', 'Bearer ' + res.token);
return (0, _get4.default)(AmbassifyApi.prototype.__proto__ || (0, _getPrototypeOf2.default)(AmbassifyApi.prototype), '_request', _this3).call(_this3, url, options);
return (0, _get4.default)(AmbassifyApi.prototype.__proto__ || (0, _getPrototypeOf2.default)(AmbassifyApi.prototype), '_request', _this4).call(_this4, url, options);
});

@@ -180,0 +246,0 @@ }

6

package.json
{
"name": "@ambassify/ambassify-client",
"version": "3.1.2",
"version": "3.2.0",
"description": "Base API client library for all Ambassify clients",

@@ -23,3 +23,3 @@ "engines": {

"@ambassify/error": "^1.0.1",
"@ambassify/fetch-api": "^3.1.1",
"@ambassify/fetch-api": "^3.2.0",
"@ambassify/json-parse-safe": "^1.1.0",

@@ -58,3 +58,3 @@ "@ambassify/throttle": "^0.1.8",

"homepage": "https://github.com/ambassify/api-clients#readme",
"gitHead": "94273bc8e0e27f96b5f47e9981d127c954e7dfbc"
"gitHead": "d4c6183700a69a252cb7e13a7831b59960207fd5"
}

@@ -6,2 +6,3 @@ const _get = require('lodash/get');

const FetchApi = require('@ambassify/fetch-api');
const AmbassifyError = require('@ambassify/error');
const { isRefreshEnabled, doRefreshToken, doCachedRefreshToken } = require('./refresh-token');

@@ -13,2 +14,55 @@

static impersonate(guardianConfig = {}, tokenOptions, clientOptions) {
const {
baseUrl = '',
clientId,
clientSecret,
guestToken,
} = guardianConfig;
const guardian = new AmbassifyApi({
baseUrl,
tokenType: 'Bearer',
token: guestToken,
});
tokenOptions = {
...tokenOptions,
grant_type: 'impersonate',
client_id: clientId,
client_secret: clientSecret,
};
return guardian.post('/token', tokenOptions).then(res => {
if (!res.ok) {
throw AmbassifyError.fromExternal({
message: 'Failed to retrieve token',
response: {
status: res.status,
statusText: res.statusText,
body: res.body,
text: JSON.stringify(res.body)
}
});
}
const { access_token, refresh_token } = res.body;
const tokenData = jwt.decode(access_token);
return new this({
tokenType: 'Bearer',
token: access_token,
refreshToken: refresh_token,
clientId,
clientSecret,
tokenEndpoint: baseUrl.replace(/\/*$/, '') + '/token',
organization: tokenData && tokenData.oid,
...clientOptions
});
});
}
static addAuthenticationOptions(options) {

@@ -15,0 +69,0 @@ // If no token is set we don't need to update any options

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc