@fleetkeep/cli 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/auth.mjs +8 -4
- package/package.json +1 -1
package/auth.mjs
CHANGED
|
@@ -39,6 +39,7 @@ export function oauthConfig() {
|
|
|
39
39
|
}
|
|
40
40
|
return {
|
|
41
41
|
origin,
|
|
42
|
+
resource: `${origin}/api`,
|
|
42
43
|
clientId: process.env.FLEETKEEP_OAUTH_CLIENT_ID || DEFAULT_CLIENT_ID,
|
|
43
44
|
redirectUri: redirect.href,
|
|
44
45
|
scopes: DEFAULT_SCOPES,
|
|
@@ -111,7 +112,7 @@ export function authorizationRequest(config = oauthConfig()) {
|
|
|
111
112
|
code_challenge: challenge,
|
|
112
113
|
code_challenge_method: 'S256',
|
|
113
114
|
state,
|
|
114
|
-
resource: config.
|
|
115
|
+
resource: config.resource,
|
|
115
116
|
prompt: 'consent'
|
|
116
117
|
}).toString();
|
|
117
118
|
return { url, state, verifier };
|
|
@@ -134,7 +135,10 @@ async function tokenRequest(parameters, config = oauthConfig()) {
|
|
|
134
135
|
});
|
|
135
136
|
const payload = await response.json().catch(() => ({}));
|
|
136
137
|
if (!response.ok || typeof payload.access_token !== 'string') {
|
|
137
|
-
const reason =
|
|
138
|
+
const reason =
|
|
139
|
+
typeof payload.error === 'string'
|
|
140
|
+
? `${payload.error}${typeof payload.error_description === 'string' ? `: ${payload.error_description}` : ''}`
|
|
141
|
+
: `HTTP ${response.status}`;
|
|
138
142
|
throw new Error(`Fleetkeep OAuth rejected the request (${reason}).`);
|
|
139
143
|
}
|
|
140
144
|
return {
|
|
@@ -160,7 +164,7 @@ export async function exchangeAuthorizationCode(code, verifier, config = oauthCo
|
|
|
160
164
|
redirect_uri: config.redirectUri,
|
|
161
165
|
client_id: config.clientId,
|
|
162
166
|
code_verifier: verifier,
|
|
163
|
-
resource: config.
|
|
167
|
+
resource: config.resource
|
|
164
168
|
},
|
|
165
169
|
config
|
|
166
170
|
);
|
|
@@ -178,7 +182,7 @@ export async function refreshStoredTokens(tokens, config = oauthConfig()) {
|
|
|
178
182
|
refresh_token: tokens.refreshToken,
|
|
179
183
|
client_id: config.clientId,
|
|
180
184
|
scope: config.scopes.join(' '),
|
|
181
|
-
resource: config.
|
|
185
|
+
resource: config.resource
|
|
182
186
|
},
|
|
183
187
|
config
|
|
184
188
|
);
|