From 455aaa69366182d5bd26ec92a25fc64e73cee0eb Mon Sep 17 00:00:00 2001 From: Manu Singh Date: Tue, 9 Apr 2024 11:45:35 -0700 Subject: [PATCH] Update EnvoyAPI.js --- lib/EnvoyAPI.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/EnvoyAPI.js b/lib/EnvoyAPI.js index 6a8ab9e..c4eeece 100644 --- a/lib/EnvoyAPI.js +++ b/lib/EnvoyAPI.js @@ -453,6 +453,17 @@ class EnvoyAPI { * @param {string} [secret=process.env.ENVOY_CLIENT_SECRET] */ static login(id = process.env.ENVOY_CLIENT_ID, secret = process.env.ENVOY_CLIENT_SECRET) { + return EnvoyAPI.login(id, secret, ['plugin', 'token.refresh']) + } + + /** + * Gets an access token using client_credentials as the grant type. + * + * @param {string} [id=process.env.ENVOY_CLIENT_ID] + * @param {string} [secret=process.env.ENVOY_CLIENT_SECRET] + * @param {string[]} [scopes] + */ + static login(id = process.env.ENVOY_CLIENT_ID, secret = process.env.ENVOY_CLIENT_SECRET, scopes) { const baseUrl = process.env.ENVOY_BASE_URL || 'https://app.envoy.com'; return request({ auth: { @@ -465,7 +476,7 @@ class EnvoyAPI { grant_type: 'client_credentials', client_id: id, client_secret: secret, - scope: 'plugin,token.refresh', + scope: scopes.join(','), }, url: '/a/auth/v0/token', baseUrl, @@ -479,6 +490,16 @@ class EnvoyAPI { password, id = process.env.ENVOY_CLIENT_ID, secret = process.env.ENVOY_CLIENT_SECRET, + ) { + return EnvoyAPI.loginAsUser(username, password, id, secret, ['plugin','token.refresh']) + } + + static loginAsUser( + username, + password, + id = process.env.ENVOY_CLIENT_ID, + secret = process.env.ENVOY_CLIENT_SECRET, + scopes, ) { const baseUrl = process.env.ENVOY_BASE_URL || 'https://app.envoy.com'; return request({ @@ -492,7 +513,7 @@ class EnvoyAPI { grant_type: 'password', username, password, - scope: 'plugin,token.refresh', + scope: scopes.join(','), }, url: '/a/auth/v0/token', baseUrl,