@magpie-community/opencode-kiro-auth 0.1.41 → 0.1.43
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/README.md +8 -3
- package/index.mjs +19 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -55,8 +55,10 @@ them, are under "Other ways to sign in…".
|
|
|
55
55
|
again the same way goes beside it rather than replacing it: magpie
|
|
56
56
|
matches a sign-in by its name, and the plugin can't see the other
|
|
57
57
|
accounts to match it by `uid`.
|
|
58
|
-
- A company's own identity provider (`external_idp`) is not
|
|
59
|
-
here. Sign in with `kiro-cli login`
|
|
58
|
+
- A company's own identity provider (`external_idp`) is not offered as a
|
|
59
|
+
browser sign-in here. Sign in with `kiro-cli login` or the Kiro IDE and
|
|
60
|
+
use the next method instead; its management calls carry
|
|
61
|
+
`TokenType: EXTERNAL_IDP`.
|
|
60
62
|
- **Kiro CLI's or Kiro IDE's sign-in**: uses the account kiro-cli is signed
|
|
61
63
|
in to, or else the Kiro IDE's. Nothing is copied. It is read each time
|
|
62
64
|
from where they keep it:
|
|
@@ -68,7 +70,10 @@ them, are under "Other ways to sign in…".
|
|
|
68
70
|
|
|
69
71
|
kiro-cli refreshes its own token first (`kiro-cli debug refresh-auth-token`).
|
|
70
72
|
A token the plugin refreshes itself is written back, so kiro-cli and the
|
|
71
|
-
IDE go on with it.
|
|
73
|
+
IDE go on with it. An external-IdP sign-in read from either source sends
|
|
74
|
+
the control-plane `TokenType` that Kiro's own clients send, and is
|
|
75
|
+
renewed by the company's identity provider itself (its token endpoint,
|
|
76
|
+
client ID and the scopes it granted), not by Kiro.
|
|
72
77
|
- **Kiro API key (`ksk_…`)**: sent with `tokentype: API_KEY`, as kiro-cli
|
|
73
78
|
sends it. `GetProfile` is asked in us-east-1, then eu-central-1, for the
|
|
74
79
|
region the key's profile is in; a key it finds none for is used in
|
package/index.mjs
CHANGED
|
@@ -193,6 +193,7 @@ async function readCLI() {
|
|
|
193
193
|
c.method = "external-idp"
|
|
194
194
|
c.clientId = m.client_id ?? ""
|
|
195
195
|
c.tokenURL = m.token_endpoint || (m.issuer_url ? m.issuer_url.replace(/\/$/, "") + "/v1/token" : "")
|
|
196
|
+
c.scope = scopeOf(m.scopes ?? m.scope)
|
|
196
197
|
}
|
|
197
198
|
return c
|
|
198
199
|
}
|
|
@@ -203,6 +204,9 @@ async function readCLI() {
|
|
|
203
204
|
return null
|
|
204
205
|
}
|
|
205
206
|
|
|
207
|
+
// scopeOf is an OAuth scope parameter from a list of scopes or one string.
|
|
208
|
+
const scopeOf = (s) => (Array.isArray(s) ? s.filter((x) => typeof x === "string" && x).join(" ") : typeof s === "string" ? s.trim() : "")
|
|
209
|
+
|
|
206
210
|
// readIDE reads the Kiro IDE's sign-in.
|
|
207
211
|
async function readIDE() {
|
|
208
212
|
const path = join(ideDir(), "kiro-auth-token.json")
|
|
@@ -213,6 +217,7 @@ async function readIDE() {
|
|
|
213
217
|
return null
|
|
214
218
|
}
|
|
215
219
|
if (!t?.accessToken) return null
|
|
220
|
+
const authMethod = String(t.authMethod ?? t.provider ?? "").toLowerCase().replace(/[^a-z]/g, "")
|
|
216
221
|
const c = { access: t.accessToken, refresh: t.refreshToken ?? "", expires: time(t.expiresAt), region: t.region || "us-east-1",
|
|
217
222
|
profile: arnOf(t.profileArn), method: "idc", idePath: path, builderID: isBuilderID(t.provider) }
|
|
218
223
|
if (t.clientIdHash) {
|
|
@@ -221,7 +226,15 @@ async function readIDE() {
|
|
|
221
226
|
;[c.clientId, c.clientSecret] = [reg.clientId ?? "", reg.clientSecret ?? ""]
|
|
222
227
|
} catch {}
|
|
223
228
|
}
|
|
224
|
-
if (
|
|
229
|
+
if (authMethod === "externalidp") {
|
|
230
|
+
// renewed by the company's own identity provider, with what the IDE
|
|
231
|
+
// keeps for it; the IdP (Entra ID) asks for the scopes it granted
|
|
232
|
+
c.method = "external-idp"
|
|
233
|
+
c.clientId = typeof t.clientId === "string" ? t.clientId : c.clientId ?? ""
|
|
234
|
+
c.tokenURL = typeof t.tokenEndpoint === "string" ? t.tokenEndpoint : ""
|
|
235
|
+
c.scope = scopeOf(t.scopes ?? t.scope)
|
|
236
|
+
} else if (authMethod === "machinetoken") c.method = "machine-token"
|
|
237
|
+
else if (authMethod === "social" || !c.clientId) c.method = "social"
|
|
225
238
|
return c
|
|
226
239
|
}
|
|
227
240
|
|
|
@@ -327,6 +340,7 @@ async function refresh(c) {
|
|
|
327
340
|
case "external-idp": {
|
|
328
341
|
if (!c.tokenURL) throw gone(EXPIRED + " with `kiro-cli login`")
|
|
329
342
|
const form = new URLSearchParams({ grant_type: "refresh_token", client_id: c.clientId ?? "", refresh_token: c.refresh })
|
|
343
|
+
if (c.scope) form.set("scope", c.scope)
|
|
330
344
|
const r = await post(c.tokenURL, "application/x-www-form-urlencoded", form.toString())
|
|
331
345
|
out = { access: r.access_token, refresh: r.refresh_token, expiresIn: r.expires_in }
|
|
332
346
|
break
|
|
@@ -347,7 +361,10 @@ function authHeaders(a) {
|
|
|
347
361
|
if (a.tokenType) h.tokentype = a.tokenType
|
|
348
362
|
return h
|
|
349
363
|
}
|
|
350
|
-
const tokenType = (c) =>
|
|
364
|
+
const tokenType = (c) => c.method === "apikey" ? "API_KEY"
|
|
365
|
+
: c.method === "external-idp" ? "EXTERNAL_IDP"
|
|
366
|
+
: c.method === "machine-token" ? "KIRO_MACHINE_TOKEN"
|
|
367
|
+
: ""
|
|
351
368
|
|
|
352
369
|
// region is where the account's API is: the region its profile is in, else
|
|
353
370
|
// the nearer of Kiro's two to where it signed in. It goes into the API's host
|