Files
hyperframes/packages/cli/src/auth/config.ts
T
Miguel Ángel 5ce6b30bdb fix(cli): billing and Desktop handoff read their hosts from settings (#6897)
* fix(cli): billing and Desktop handoff read their hosts from settings

* fix(cli): OAuth client and API hosts read from settings

* test(cli): host and client settings tests run the same on any machine

* chore(cli): format and refresh the skills manifest

* chore(cli): trim a comment

* chore(cli): keep the stylesheet as it was
2026-10-31 22:49:12 +00:00

57 lines
1.8 KiB
TypeScript

import { AuthError, ErrOAuthNotConfigured } from "./errors.js";
const PROD_CLIENT_ID = "Zg3LF4FCLoeJoGs2YqMtZ17g";
export function oauthEnvironment(): "prod" | "dev" {
const value = process.env["HYPERFRAMES_ENV"] || "prod";
if (value === "prod" || value === "dev") return value;
throw new AuthError("OAUTH_NOT_CONFIGURED", "HYPERFRAMES_ENV must be prod or dev");
}
export function defaultClientId(): string {
return PROD_CLIENT_ID;
}
export function resolveClientId(): string {
const id = process.env["HYPERFRAMES_OAUTH_CLIENT_ID"] || defaultClientId();
if (!id) throw ErrOAuthNotConfigured();
return id;
}
export function tokenEndpoint(): string {
return process.env["HYPERFRAMES_OAUTH_TOKEN_URL"] || "https://api2.heygen.com/v1/oauth/token";
}
export function authorizeEndpoint(): string {
return process.env["HYPERFRAMES_OAUTH_AUTHORIZE_URL"] || "https://app.heygen.com/oauth/authorize";
}
export function revokeEndpoint(): string {
return process.env["HYPERFRAMES_OAUTH_REVOKE_URL"] || "https://api2.heygen.com/v1/oauth/revoke";
}
export function deviceAuthorizationEndpoint(): string {
return (
process.env["HYPERFRAMES_OAUTH_DEVICE_URL"] ||
"https://api2.heygen.com/v1/oauth/device_authorization"
);
}
export function oauthIdentity(): { client_id: string; token_endpoint: string } {
return { client_id: resolveClientId(), token_endpoint: tokenEndpoint() };
}
export function assertOAuthIdentity(tokens: { client_id?: string; token_endpoint?: string }): void {
const identity = oauthIdentity();
if (
tokens.client_id !== identity.client_id ||
tokens.token_endpoint !== identity.token_endpoint
) {
throw new AuthError(
"LOGIN_EXPIRED",
"This login belongs to a different OAuth client or environment",
"Run `hyperframes auth login` to sign into the selected HyperFrames environment.",
);
}
}