Skip to content

Commit b84c228

Browse files
committed
use TRIGGER_ACCESS_TOKEN
1 parent fd8bf06 commit b84c228

4 files changed

Lines changed: 52 additions & 61 deletions

File tree

.changeset/deploy-api-keys.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"trigger.dev": patch
33
---
44

5-
Allow `trigger deploy` to authenticate with an environment API key from `TRIGGER_SECRET_KEY`, including deploy-only keys and Preview deployments.
5+
Allow `trigger deploy` to authenticate with an environment API key from `TRIGGER_ACCESS_TOKEN`.

packages/cli-v3/src/commands/deploy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ async function _deployCommand(dir: string, options: DeployCommandOptions) {
270270
verifyDirectory(dir, projectPath);
271271

272272
const authorization = await authenticateForDeploy({
273-
secretKey: process.env.TRIGGER_SECRET_KEY,
273+
accessToken: process.env.TRIGGER_ACCESS_TOKEN,
274274
apiUrl: process.env.TRIGGER_API_URL ?? options.apiUrl,
275275
profile: options.profile,
276276
silent: options.plain,

packages/cli-v3/src/deploy/auth.test.ts

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import { authenticateForDeploy, userIdForDeploy } from "./auth.js";
88
import { readAuthConfigProfile } from "../utilities/configFiles.js";
99

1010
describe("authenticateForDeploy", () => {
11-
it("gives TRIGGER_SECRET_KEY precedence without logging in", async () => {
11+
it("uses an API key from TRIGGER_ACCESS_TOKEN without logging in", async () => {
1212
let loginCalled = false;
1313

1414
const result = await authenticateForDeploy({
15-
secretKey: "tr_prod_sk_deploy",
15+
accessToken: "tr_prod_sk_deploy",
1616
apiUrl: "https://example.trigger.dev",
1717
profile: "default",
1818
silent: true,
@@ -37,7 +37,7 @@ describe("authenticateForDeploy", () => {
3737

3838
it("derives hosted dashboard links without user metadata", async () => {
3939
const result = await authenticateForDeploy({
40-
secretKey: "tr_preview_sk_deploy",
40+
accessToken: "tr_preview_sk_deploy",
4141
apiUrl: "https://api.example.trigger.dev",
4242
profile: "default",
4343
silent: true,
@@ -52,7 +52,7 @@ describe("authenticateForDeploy", () => {
5252

5353
it("uses the normal cloud URLs when no API URL is set", async () => {
5454
const result = await authenticateForDeploy({
55-
secretKey: "tr_prod_sk_deploy",
55+
accessToken: "tr_prod_sk_deploy",
5656
profile: "default",
5757
silent: true,
5858
login: async () => ({ ok: false, error: "should not be called" }),
@@ -70,7 +70,7 @@ describe("authenticateForDeploy", () => {
7070
});
7171

7272
const result = await authenticateForDeploy({
73-
secretKey: "tr_prod_sk_deploy",
73+
accessToken: "tr_prod_sk_deploy",
7474
profile: "selfhosted",
7575
silent: true,
7676
login: async () => ({ ok: false, error: "should not be called" }),
@@ -88,7 +88,7 @@ describe("authenticateForDeploy", () => {
8888
});
8989

9090
const result = await authenticateForDeploy({
91-
secretKey: "tr_prod_sk_deploy",
91+
accessToken: "tr_prod_sk_deploy",
9292
apiUrl: "https://api.trigger.dev",
9393
profile: "selfhosted",
9494
silent: true,
@@ -100,9 +100,10 @@ describe("authenticateForDeploy", () => {
100100
});
101101
});
102102

103-
it("keeps login authentication when no secret key is set", async () => {
103+
it("passes a PAT through to the login path", async () => {
104104
let loginOptions: unknown;
105105
const result = await authenticateForDeploy({
106+
accessToken: "tr_pat_abc123",
106107
apiUrl: "https://example.trigger.dev",
107108
profile: "ci",
108109
silent: false,
@@ -121,52 +122,53 @@ describe("authenticateForDeploy", () => {
121122
expect(result).toEqual({ ok: false, error: "login result" });
122123
});
123124

124-
it("rejects a PAT in TRIGGER_SECRET_KEY with a helpful error", async () => {
125-
const result = await authenticateForDeploy({
126-
secretKey: "tr_pat_abc123",
127-
profile: "default",
128-
silent: true,
129-
login: async () => ({ ok: false, error: "should not be called" }),
130-
});
131-
132-
expect(result).toEqual({
133-
ok: false,
134-
error: expect.stringContaining("TRIGGER_ACCESS_TOKEN"),
135-
});
136-
});
137-
138-
it("rejects an OAT in TRIGGER_SECRET_KEY with a helpful error", async () => {
125+
it("passes an OAT through to the login path", async () => {
126+
let loginOptions: unknown;
139127
const result = await authenticateForDeploy({
140-
secretKey: "tr_oat_abc123",
141-
profile: "default",
142-
silent: true,
143-
login: async () => ({ ok: false, error: "should not be called" }),
128+
accessToken: "tr_oat_abc123",
129+
apiUrl: "https://example.trigger.dev",
130+
profile: "ci",
131+
silent: false,
132+
login: async (options) => {
133+
loginOptions = options;
134+
return { ok: false, error: "login result" };
135+
},
144136
});
145137

146-
expect(result).toEqual({
147-
ok: false,
148-
error: expect.stringContaining("TRIGGER_ACCESS_TOKEN"),
138+
expect(loginOptions).toEqual({
139+
embedded: true,
140+
defaultApiUrl: "https://example.trigger.dev",
141+
profile: "ci",
142+
silent: false,
149143
});
144+
expect(result).toEqual({ ok: false, error: "login result" });
150145
});
151146

152-
it("rejects a secret key that doesn't look like an API key", async () => {
147+
it("keeps login authentication when no access token is set", async () => {
148+
let loginOptions: unknown;
153149
const result = await authenticateForDeploy({
154-
secretKey: "not-a-valid-key",
155-
profile: "default",
156-
silent: true,
157-
login: async () => ({ ok: false, error: "should not be called" }),
150+
apiUrl: "https://example.trigger.dev",
151+
profile: "ci",
152+
silent: false,
153+
login: async (options) => {
154+
loginOptions = options;
155+
return { ok: false, error: "login result" };
156+
},
158157
});
159158

160-
expect(result).toEqual({
161-
ok: false,
162-
error: expect.stringContaining("does not look like a Trigger.dev API key"),
159+
expect(loginOptions).toEqual({
160+
embedded: true,
161+
defaultApiUrl: "https://example.trigger.dev",
162+
profile: "ci",
163+
silent: false,
163164
});
165+
expect(result).toEqual({ ok: false, error: "login result" });
164166
});
165167

166168
it("throws a descriptive error for an invalid API URL", async () => {
167169
await expect(
168170
authenticateForDeploy({
169-
secretKey: "tr_prod_sk_deploy",
171+
accessToken: "tr_prod_sk_deploy",
170172
apiUrl: "not-a-url",
171173
profile: "default",
172174
silent: true,

packages/cli-v3/src/deploy/auth.ts

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ type LoginForDeploy = (options: {
2727
}) => Promise<LoginResult>;
2828

2929
export async function authenticateForDeploy({
30-
secretKey,
30+
accessToken,
3131
apiUrl,
3232
profile,
3333
silent,
3434
login,
3535
}: {
36-
secretKey?: string;
36+
accessToken?: string;
3737
apiUrl?: string;
3838
profile: string;
3939
silent: boolean;
@@ -42,7 +42,13 @@ export async function authenticateForDeploy({
4242
const authConfig = readAuthConfigProfile(profile);
4343
const resolvedApiUrl = apiUrl ?? authConfig?.apiUrl ?? CLOUD_API_URL;
4444

45-
if (!secretKey) {
45+
const isApiKey =
46+
!!accessToken &&
47+
accessToken.startsWith(apiKeyPrefix) &&
48+
!accessToken.startsWith(personalTokenPrefix) &&
49+
!accessToken.startsWith(organizationTokenPrefix);
50+
51+
if (!isApiKey) {
4652
return login({
4753
embedded: true,
4854
defaultApiUrl: resolvedApiUrl,
@@ -51,30 +57,13 @@ export async function authenticateForDeploy({
5157
});
5258
}
5359

54-
if (secretKey.startsWith(personalTokenPrefix) || secretKey.startsWith(organizationTokenPrefix)) {
55-
return {
56-
ok: false,
57-
error: `TRIGGER_SECRET_KEY is set to a ${
58-
secretKey.startsWith(personalTokenPrefix) ? "Personal" : "Organization"
59-
} Access Token. Use TRIGGER_ACCESS_TOKEN instead, or remove TRIGGER_SECRET_KEY and use \`trigger login\`.`,
60-
};
61-
}
62-
63-
if (!secretKey.startsWith(apiKeyPrefix)) {
64-
return {
65-
ok: false,
66-
error:
67-
"TRIGGER_SECRET_KEY does not look like a Trigger.dev API key. API keys start with \`tr_\` (e.g. \`tr_prod_...\`).",
68-
};
69-
}
70-
7160
return {
7261
ok: true,
7362
profile,
7463
dashboardUrl: dashboardUrlForApiUrl(resolvedApiUrl),
7564
auth: {
7665
apiUrl: resolvedApiUrl,
77-
accessToken: secretKey,
66+
accessToken,
7867
tokenType: "apiKey",
7968
},
8069
};

0 commit comments

Comments
 (0)