@magpie-community/opencode-kiro-auth 0.1.42 → 0.1.44

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 CHANGED
@@ -71,7 +71,9 @@ them, are under "Other ways to sign in…".
71
71
  kiro-cli refreshes its own token first (`kiro-cli debug refresh-auth-token`).
72
72
  A token the plugin refreshes itself is written back, so kiro-cli and the
73
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.
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.
75
77
  - **Kiro API key (`ksk_…`)**: sent with `tokentype: API_KEY`, as kiro-cli
76
78
  sends it. `GetProfile` is asked in us-east-1, then eu-central-1, for the
77
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")
@@ -222,8 +226,14 @@ async function readIDE() {
222
226
  ;[c.clientId, c.clientSecret] = [reg.clientId ?? "", reg.clientSecret ?? ""]
223
227
  } catch {}
224
228
  }
225
- if (authMethod === "externalidp") c.method = "external-idp"
226
- else if (authMethod === "machinetoken") c.method = "machine-token"
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"
227
237
  else if (authMethod === "social" || !c.clientId) c.method = "social"
228
238
  return c
229
239
  }
@@ -330,6 +340,7 @@ async function refresh(c) {
330
340
  case "external-idp": {
331
341
  if (!c.tokenURL) throw gone(EXPIRED + " with `kiro-cli login`")
332
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)
333
344
  const r = await post(c.tokenURL, "application/x-www-form-urlencoded", form.toString())
334
345
  out = { access: r.access_token, refresh: r.refresh_token, expiresIn: r.expires_in }
335
346
  break
package/opencode2.mjs CHANGED
@@ -507,6 +507,14 @@ async function setupPlugin(ctx, fn, live) {
507
507
  // the account the list was last read for: a credential.updated that
508
508
  // leaves it as it was reads nothing again
509
509
  let readFor = null
510
+ // the last list each account's own read gave, by the account it was read
511
+ // for: a read that fails (a workspace config answering 503) keeps the
512
+ // list that same account last read rather than the bundled one, which
513
+ // brought back models its workspace hides (plugins#1642). Another
514
+ // account's list is never used, a read that gave an empty list is kept
515
+ // as empty, and the bundled list stands in only for an account whose
516
+ // list was never read.
517
+ const lists = new Map()
510
518
  const stateOf = async () => {
511
519
  const c = await ctx.integration.connection.active(authID).catch(() => undefined)
512
520
  const a = c ? await getAuth(authID) : undefined
@@ -523,7 +531,8 @@ async function setupPlugin(ctx, fn, live) {
523
531
  const s = source.get(authID)
524
532
  const connection = await ctx.integration.connection.active(authID).catch(() => undefined)
525
533
  const a = connection ? await getAuth(authID) : undefined
526
- readFor = connKey(connection) + "\0" + (a ? fingerprint(a) : "")
534
+ const readingFor = connKey(connection) + "\0" + (a ? fingerprint(a) : "")
535
+ readFor = readingFor
527
536
  if (!a || listID !== authID || typeof hooks.provider?.models !== "function") {
528
537
  if (s.connection || s.models) {
529
538
  s.connection = undefined
@@ -544,7 +553,12 @@ async function setupPlugin(ctx, fn, live) {
544
553
  return
545
554
  }
546
555
  s.connection = connection
547
- s.models = got && typeof got === "object" ? Object.entries(got).map(([k, m]) => modelOf(authID, s.prov, k, record(m))) : null
556
+ if (got && typeof got === "object") {
557
+ s.models = Object.entries(got).map(([k, m]) => modelOf(authID, s.prov, k, record(m)))
558
+ lists.delete(readingFor)
559
+ lists.set(readingFor, s.models)
560
+ if (lists.size > 32) lists.delete(lists.keys().next().value)
561
+ } else s.models = lists.get(readingFor) ?? null
548
562
  await ctx.provider.reload()
549
563
  await ctx.model?.reload?.()
550
564
  } finally {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magpie-community/opencode-kiro-auth",
3
- "version": "0.1.42",
3
+ "version": "0.1.44",
4
4
  "description": "Kiro subscriptions (Free, Pro, Pro+, Power) in OpenCode and magpie",
5
5
  "type": "module",
6
6
  "main": "./opencode.mjs",