From 836e7f663e6f3ee080a3000fb71a8891b41d5a00 Mon Sep 17 00:00:00 2001 From: fosten Date: Thu, 27 Jul 2023 05:20:09 -0400 Subject: [PATCH 1/2] Add scope and client_secret --- src/client/oauth.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/client/oauth.js b/src/client/oauth.js index 36f521c..3531ddf 100644 --- a/src/client/oauth.js +++ b/src/client/oauth.js @@ -12,6 +12,8 @@ import axios from 'axios'; * @param {Object} authOptions * @property {String} authOptions.host * @property {String} authOptions.clientId + * @property {String} [options.clientSecret] + * @property {String} [options.scope] * @property {Function} [authOptions.getToken] * @property {Function} [authOptions.setToken] * @returns {Object} @@ -21,6 +23,8 @@ export default function oAuth(request, authOptions) { const { host = '', clientId = '', + clientSecret = '', + scope = '', getToken = () => memToken, setToken = (t) => { memToken = t; }, } = authOptions; @@ -163,7 +167,7 @@ export default function oAuth(request, authOptions) { 'Content-Type': 'application/x-www-form-urlencoded', Accept: 'json', }, - data: `grant_type=password&username=${user}&password=${password}&client_id=${clientId}`, + data: `grant_type=password&username=${user}&password=${password}&client_id=${clientId}&scope=${scope}&client_secret=${clientSecret}`, }).then(res => parseToken(res.data)).catch((error) => { throw error; }), getToken, }; From 763d4c71902a1ac8754488897911416026081864 Mon Sep 17 00:00:00 2001 From: fosten Date: Tue, 9 Apr 2024 18:13:36 -0400 Subject: [PATCH 2/2] Change grant_type to client_credentials --- src/client/oauth.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/oauth.js b/src/client/oauth.js index 3531ddf..b532275 100644 --- a/src/client/oauth.js +++ b/src/client/oauth.js @@ -167,7 +167,7 @@ export default function oAuth(request, authOptions) { 'Content-Type': 'application/x-www-form-urlencoded', Accept: 'json', }, - data: `grant_type=password&username=${user}&password=${password}&client_id=${clientId}&scope=${scope}&client_secret=${clientSecret}`, + data: `grant_type=client_credentials&username=${user}&password=${password}&client_id=${clientId}&scope=${scope}&client_secret=${clientSecret}`, }).then(res => parseToken(res.data)).catch((error) => { throw error; }), getToken, };