@fleetkeep/cli 0.1.0 → 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 +17 -6
- 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 };
|
|
@@ -125,12 +126,19 @@ export function authorizationRequest(config = oauthConfig()) {
|
|
|
125
126
|
async function tokenRequest(parameters, config = oauthConfig()) {
|
|
126
127
|
const response = await fetch(config.tokenEndpoint, {
|
|
127
128
|
method: 'POST',
|
|
128
|
-
headers: {
|
|
129
|
+
headers: {
|
|
130
|
+
'content-type': 'application/x-www-form-urlencoded',
|
|
131
|
+
accept: 'application/json',
|
|
132
|
+
origin: config.origin
|
|
133
|
+
},
|
|
129
134
|
body: new URLSearchParams(parameters)
|
|
130
135
|
});
|
|
131
136
|
const payload = await response.json().catch(() => ({}));
|
|
132
137
|
if (!response.ok || typeof payload.access_token !== 'string') {
|
|
133
|
-
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}`;
|
|
134
142
|
throw new Error(`Fleetkeep OAuth rejected the request (${reason}).`);
|
|
135
143
|
}
|
|
136
144
|
return {
|
|
@@ -156,7 +164,7 @@ export async function exchangeAuthorizationCode(code, verifier, config = oauthCo
|
|
|
156
164
|
redirect_uri: config.redirectUri,
|
|
157
165
|
client_id: config.clientId,
|
|
158
166
|
code_verifier: verifier,
|
|
159
|
-
resource: config.
|
|
167
|
+
resource: config.resource
|
|
160
168
|
},
|
|
161
169
|
config
|
|
162
170
|
);
|
|
@@ -174,7 +182,7 @@ export async function refreshStoredTokens(tokens, config = oauthConfig()) {
|
|
|
174
182
|
refresh_token: tokens.refreshToken,
|
|
175
183
|
client_id: config.clientId,
|
|
176
184
|
scope: config.scopes.join(' '),
|
|
177
|
-
resource: config.
|
|
185
|
+
resource: config.resource
|
|
178
186
|
},
|
|
179
187
|
config
|
|
180
188
|
);
|
|
@@ -290,7 +298,10 @@ export async function logout() {
|
|
|
290
298
|
const config = oauthConfig();
|
|
291
299
|
await fetch(config.revocationEndpoint, {
|
|
292
300
|
method: 'POST',
|
|
293
|
-
headers: {
|
|
301
|
+
headers: {
|
|
302
|
+
'content-type': 'application/x-www-form-urlencoded',
|
|
303
|
+
origin: config.origin
|
|
304
|
+
},
|
|
294
305
|
body: new URLSearchParams({
|
|
295
306
|
token: stored.refreshToken,
|
|
296
307
|
token_type_hint: 'refresh_token',
|