Skip to content

Commit 7bbce58

Browse files
committed
fix(auth): share environment header validation
1 parent f2530cf commit 7bbce58

2 files changed

Lines changed: 14 additions & 15 deletions

File tree

‎packages/cli/src/auth/resolver.ts‎

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,27 +50,18 @@ export interface ResolveOptions {
5050
export async function resolveCredential(opts: ResolveOptions = {}): Promise<ResolvedCredential> {
5151
const now = (opts.now ?? (() => new Date()))();
5252

53-
const heygenEnv = process.env["HEYGEN_API_KEY"];
54-
if (heygenEnv && heygenEnv.length > 0) {
55-
if (!isHeaderSafe(heygenEnv)) {
56-
throw ErrInvalidStore("HEYGEN_API_KEY contains control characters");
57-
}
53+
const heygenEnv = headerSafeEnv("HEYGEN_API_KEY");
54+
if (heygenEnv) {
5855
return { type: "api_key", key: heygenEnv, source: "env" };
5956
}
6057

61-
const hfEnv = process.env["HYPERFRAMES_API_KEY"];
62-
if (hfEnv && hfEnv.length > 0) {
63-
if (!isHeaderSafe(hfEnv)) {
64-
throw ErrInvalidStore("HYPERFRAMES_API_KEY contains control characters");
65-
}
58+
const hfEnv = headerSafeEnv("HYPERFRAMES_API_KEY");
59+
if (hfEnv) {
6660
return { type: "api_key", key: hfEnv, source: "env_alias" };
6761
}
6862

69-
const accessToken = process.env["HEYGEN_ACCESS_TOKEN"];
63+
const accessToken = headerSafeEnv("HEYGEN_ACCESS_TOKEN");
7064
if (accessToken) {
71-
if (!isHeaderSafe(accessToken)) {
72-
throw ErrInvalidStore("HEYGEN_ACCESS_TOKEN contains control characters");
73-
}
7465
return { type: "oauth", access_token: accessToken, source: "env_oauth", refreshable: false };
7566
}
7667

@@ -87,6 +78,14 @@ export async function resolveCredential(opts: ResolveOptions = {}): Promise<Reso
8778
throw credentials.oauth ? ErrLoginExpired() : ErrNotConfigured();
8879
}
8980

81+
function headerSafeEnv(name: string): string | undefined {
82+
const value = process.env[name];
83+
if (value && !isHeaderSafe(value)) {
84+
throw ErrInvalidStore(`${name} contains control characters`);
85+
}
86+
return value;
87+
}
88+
9089
/** Like `resolveCredential` but returns `null` instead of throwing `NOT_CONFIGURED`. */
9190
export async function tryResolveCredential(
9291
opts: ResolveOptions = {},

‎skills-manifest.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"files": 1
5555
},
5656
"media-use": {
57-
"hash": "b07cf8ba10a8ac7b",
57+
"hash": "92f4c2d04884b10d",
5858
"files": 109
5959
},
6060
"motion-graphics": {

0 commit comments

Comments
 (0)