Skip to content

Commit

Permalink
Update EnvoyAPI.js
Browse files Browse the repository at this point in the history
  • Loading branch information
manuenvoy committed Apr 9, 2024
1 parent 946f052 commit 455aaa6
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions lib/EnvoyAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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,
Expand All @@ -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({
Expand All @@ -492,7 +513,7 @@ class EnvoyAPI {
grant_type: 'password',
username,
password,
scope: 'plugin,token.refresh',
scope: scopes.join(','),
},
url: '/a/auth/v0/token',
baseUrl,
Expand Down

0 comments on commit 455aaa6

Please sign in to comment.