Files
cp1-agents/scripts/kab_token.py
Jonathan Boniface f659564208 Platform scripts, MCP servers, deployment and docs for the KAB runs
- Scripts to run workflows from a YAML context or run inputs (kab_run_workflow.py, with
  --input name=@file), store per-project discovery connections, bootstrap agent MCP keys,
  refresh the KAB token, publish reports and build estate snapshots.
- Hyperscaler discovery servers extended in place; cloud-knowledge folded into them.
- deploy/crucible-kab-dev.yaml: the Discovery package agent and the Assessment agents.
- Platform issue write-ups and current-wiring notes under docs/platform-issues/.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 22:13:25 +00:00

43 lines
1.6 KiB
Python

#!/usr/bin/env python3
"""Turn a KAB refresh token into a fresh access token, in ~/.kab_token.
Paste the browser's refresh_token at the prompt. It isn't echoed, and it isn't stored: it's a stronger credential than
the access token, so it stays out of files and shell history. Run this just before a script that needs a token.
Usage: python3 scripts/kab_token.py
"""
import getpass
import json
import os
import sys
import time
import urllib.error
import urllib.parse
import urllib.request
from pathlib import Path
TOKEN_URL = "https://id.kab-dev.kyndemo.live/realms/kab/protocol/openid-connect/token"
CLIENT = "kab-ui"
def main() -> int:
refresh = getpass.getpass("KAB refresh_token: ").strip()
body = urllib.parse.urlencode({"grant_type": "refresh_token", "client_id": CLIENT, "refresh_token": refresh}).encode()
try:
with urllib.request.urlopen(urllib.request.Request(TOKEN_URL, data=body), timeout=30) as response:
reply = json.load(response)
except urllib.error.HTTPError as error:
print(f"Refused: HTTP {error.code}: {json.loads(error.read() or b'{}').get('error_description', 'no reason given')}")
return 1
path = Path.home() / ".kab_token"
descriptor = os.open(path, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600)
with os.fdopen(descriptor, "w") as out:
out.write(reply["access_token"])
print(f"Wrote {path}. It lasts {reply.get('expires_in')} s, until {time.strftime('%H:%M:%S', time.localtime(time.time() + reply.get('expires_in', 0)))}.")
return 0
if __name__ == "__main__":
sys.exit(main())