Skip to content

Commit d4c1caa

Browse files
atrakhConvex, Inc.
authored andcommitted
Remove Auth0 login flows (#40145)
GitOrigin-RevId: 22d9bbb8135138ef85c0ba2cd6bae303a50cfcac
1 parent 2c2ff94 commit d4c1caa

File tree

2 files changed

+22
-27
lines changed

2 files changed

+22
-27
lines changed

src/cli/lib/login.ts

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ import {
3131
} from "./utils/globalConfig.js";
3232
import { updateBigBrainAuthAfterLogin } from "./deploymentSelection.js";
3333

34-
const SCOPE = "openid email profile";
35-
/// This value was created long ago, and cannot be changed easily.
36-
/// It's just a fixed string used for identifying the Auth0 token, so it's fine
37-
/// and not user-facing.
38-
const AUDIENCE = "https://console.convex.dev/api/";
39-
4034
// Per https://github.com/panva/node-openid-client/tree/main/docs#customizing
4135
custom.setHttpOptionsDefaults({
4236
timeout: parseInt(process.env.OPENID_CLIENT_TIMEOUT || "10000"),
@@ -92,7 +86,7 @@ export async function checkAuthorization(
9286

9387
async function performDeviceAuthorization(
9488
ctx: Context,
95-
auth0Client: BaseClient,
89+
authClient: BaseClient,
9690
shouldOpen: boolean,
9791
): Promise<string> {
9892
// Device authorization flow follows this guide: https://github.com/auth0/auth0-device-flow-cli-sample/blob/9f0f3b76a6cd56ea8d99e76769187ea5102d519d/cli.js
@@ -126,12 +120,9 @@ async function performDeviceAuthorization(
126120
// Get authentication URL
127121
let handle;
128122
try {
129-
handle = await auth0Client.deviceAuthorization({
130-
scope: SCOPE,
131-
audience: AUDIENCE,
132-
});
123+
handle = await authClient.deviceAuthorization();
133124
} catch {
134-
// We couldn't get verification URL from Auth0, proceed with manual auth
125+
// We couldn't get verification URL from the auth provider, proceed with manual auth
135126
return promptString(ctx, {
136127
message:
137128
"Open https://dashboard.convex.dev/auth, log in and paste the token here:",
@@ -223,29 +214,34 @@ async function performDeviceAuthorization(
223214

224215
async function performPasswordAuthentication(
225216
ctx: Context,
226-
issuer: string,
227217
clientId: string,
228218
username: string,
229219
password: string,
230220
): Promise<string> {
221+
if (!process.env.WORKOS_API_SECRET) {
222+
return await ctx.crash({
223+
exitCode: 1,
224+
errorType: "fatal",
225+
printedMessage: "WORKOS_API_SECRET environment variable is not set",
226+
});
227+
}
228+
231229
// Unfortunately, `openid-client` doesn't support the resource owner password credentials flow so we need to manually send the requests.
232230
const options: Parameters<typeof throwingFetch>[1] = {
233231
method: "POST",
234-
headers: { "Content-Type": "application/x-www-form-urlencoded" },
235-
body: new URLSearchParams({
232+
headers: { "Content-Type": "application/json" },
233+
body: JSON.stringify({
236234
grant_type: "password",
237-
username: username,
235+
email: username,
238236
password: password,
239-
scope: SCOPE,
240237
client_id: clientId,
241-
audience: AUDIENCE,
242-
// Note that there is no client secret provided, as Auth0 refuses to require it for untrusted apps.
238+
client_secret: process.env.WORKOS_API_SECRET,
243239
}),
244240
};
245241

246242
try {
247243
const response = await throwingFetch(
248-
new URL("/oauth/token", issuer).href,
244+
"https://apiauth.convex.dev/user_management/authenticate",
249245
options,
250246
);
251247
const data = await response.json();
@@ -326,7 +322,7 @@ export async function performLogin(
326322
}
327323

328324
const issuer = overrideAuthUrl ?? "https://auth.convex.dev";
329-
let auth0;
325+
let authIssuer;
330326
let accessToken: string;
331327

332328
if (loginFlow === "paste" || (loginFlow === "auto" && isWebContainer())) {
@@ -336,7 +332,7 @@ export async function performLogin(
336332
});
337333
} else {
338334
try {
339-
auth0 = await Issuer.discover(issuer);
335+
authIssuer = await Issuer.discover(issuer);
340336
} catch {
341337
// Couldn't contact https://auth.convex.dev/.well-known/openid-configuration,
342338
// proceed with manual auth.
@@ -348,9 +344,9 @@ export async function performLogin(
348344
}
349345

350346
// typical path
351-
if (auth0) {
347+
if (authIssuer) {
352348
const clientId = overrideAuthClient ?? "HFtA247jp9iNs08NTLIB7JsNPMmRIyfi";
353-
const auth0Client = new auth0.Client({
349+
const authClient = new authIssuer.Client({
354350
client_id: clientId,
355351
token_endpoint_auth_method: "none",
356352
id_token_signed_response_alg: "RS256",
@@ -361,15 +357,14 @@ export async function performLogin(
361357
} else if (overrideAuthUsername && overrideAuthPassword) {
362358
accessToken = await performPasswordAuthentication(
363359
ctx,
364-
issuer,
365360
clientId,
366361
overrideAuthUsername,
367362
overrideAuthPassword,
368363
);
369364
} else {
370365
accessToken = await performDeviceAuthorization(
371366
ctx,
372-
auth0Client,
367+
authClient,
373368
open ?? true,
374369
);
375370
}

src/cli/lib/utils/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,7 @@ export function deploymentFetch(
11611161

11621162
/**
11631163
* Whether this is likely to be a WebContainer,
1164-
* WebContainers can't complete the Auth0 login but where that login flow
1164+
* WebContainers can't complete the WorkOS login but where that login flow
11651165
* fails has changed with the environment.
11661166
*/
11671167
export function isWebContainer(): boolean {

0 commit comments

Comments
 (0)