@agentage/cli 0.66.0 → 0.66.1
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.
|
@@ -9,4 +9,5 @@ export declare const assertPatShape: (value: string) => string;
|
|
|
9
9
|
export declare const rawPatToken: (opts?: PatOptions) => string | undefined;
|
|
10
10
|
export declare const patAuthState: (token: string, fqdn?: string) => AuthState;
|
|
11
11
|
export declare const jwtPatExpiry: (token: string) => string | null;
|
|
12
|
+
export declare const jwtPatIssuer: (token: string) => string | undefined;
|
|
12
13
|
export declare const resolveAuth: (opts?: PatOptions, read?: () => AuthState | null) => AuthState | null;
|
|
@@ -32,23 +32,42 @@ export const rawPatToken = (opts = {}) => {
|
|
|
32
32
|
// OAuth access token would. `kind: 'pat'` marks it so refresh / OAuth-session-only paths can fail
|
|
33
33
|
// with a clear message instead of attempting an impossible refresh. siteFqdn is pinned to the
|
|
34
34
|
// current target so the env-mismatch guard never fires (a PAT is not tied to a stored environment).
|
|
35
|
-
export const patAuthState = (token, fqdn = siteFqdn()) =>
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
35
|
+
export const patAuthState = (token, fqdn = siteFqdn()) => {
|
|
36
|
+
const accessToken = assertPatShape(token);
|
|
37
|
+
const issuer = jwtPatIssuer(accessToken);
|
|
38
|
+
return {
|
|
39
|
+
siteFqdn: fqdn,
|
|
40
|
+
clientId: 'pat',
|
|
41
|
+
kind: 'pat',
|
|
42
|
+
tokens: { accessToken },
|
|
43
|
+
...(issuer && { issuer }),
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
// A JWT PAT (aga_<jwt>) is not introspectable: its claims are read here, the platform verifies it.
|
|
47
|
+
const jwtPatClaims = (token) => {
|
|
43
48
|
const payload = token.slice(PAT_PREFIX.length).split('.')[1] ?? '';
|
|
44
49
|
try {
|
|
45
|
-
const
|
|
46
|
-
return typeof
|
|
50
|
+
const claims = JSON.parse(Buffer.from(payload, 'base64url').toString());
|
|
51
|
+
return typeof claims === 'object' && claims !== null ? claims : {};
|
|
47
52
|
}
|
|
48
53
|
catch {
|
|
49
|
-
return
|
|
54
|
+
return {};
|
|
50
55
|
}
|
|
51
56
|
};
|
|
57
|
+
export const jwtPatExpiry = (token) => {
|
|
58
|
+
const { exp } = jwtPatClaims(token);
|
|
59
|
+
return typeof exp === 'number' ? new Date(exp * 1000).toISOString() : null;
|
|
60
|
+
};
|
|
61
|
+
const LOOPBACK = new Set(['localhost', '127.0.0.1']);
|
|
62
|
+
// The issuer origin of a JWT PAT (https, or http on a loopback host); an opaque PAT has none.
|
|
63
|
+
export const jwtPatIssuer = (token) => {
|
|
64
|
+
const { iss } = jwtPatClaims(token);
|
|
65
|
+
if (typeof iss !== 'string' || !URL.canParse(iss))
|
|
66
|
+
return undefined;
|
|
67
|
+
const url = new URL(iss);
|
|
68
|
+
const ok = url.protocol === 'https:' || (url.protocol === 'http:' && LOOPBACK.has(url.hostname));
|
|
69
|
+
return ok ? url.origin : undefined;
|
|
70
|
+
};
|
|
52
71
|
// Resolve the active credential with precedence flag > env PAT > stored OAuth. When a PAT is
|
|
53
72
|
// present the OAuth/DCR flow is skipped entirely and the PAT is the bearer; otherwise fall back to
|
|
54
73
|
// the stored OAuth session on disk (null when signed out).
|
|
@@ -10,7 +10,7 @@ export const credentialLinks = (auth) => {
|
|
|
10
10
|
export const detectEnvMismatch = (auth, targetFqdn, targetIssuer = links(normalizeFqdn(targetFqdn)).auth) => {
|
|
11
11
|
const credentialFqdn = normalizeFqdn(auth.siteFqdn);
|
|
12
12
|
const target = normalizeFqdn(targetFqdn);
|
|
13
|
-
if (auth.kind === 'pat' || credentialLinks(auth).auth === targetIssuer)
|
|
13
|
+
if ((auth.kind === 'pat' && !auth.issuer) || credentialLinks(auth).auth === targetIssuer)
|
|
14
14
|
return null;
|
|
15
15
|
return {
|
|
16
16
|
credentialFqdn,
|