Skip to content

Commit 4a0eb59

Browse files
committed
allow devdogsuga.org in oauth flows
1 parent d7a3207 commit 4a0eb59

2 files changed

Lines changed: 18 additions & 9 deletions

File tree

src/server/auth/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ export async function handleOAuthRedirect(request: NextRequest) {
133133

134134
// A user is trying to "Sign in with DevDogs" via OAuth
135135
if ("redirect_uri" in params) {
136-
console.log(params.client_id !== env.SHARED_AUTH_CLIENT_ID);
137136
const [insertedAuthorization] = await db
138137
.insert(authorizationCodes)
139138
.values({

src/server/auth/schema.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { db } from "../db";
33
import { addSeconds } from "date-fns";
44
import { oauthStates } from "../db/schema/tables";
55
import { eq } from "drizzle-orm";
6+
import { env } from "~/env";
67

78
const authorizationCode = z.object({
89
code: z.string(),
@@ -39,15 +40,24 @@ const completeOAuthFlow = z.object({
3940
.nonoptional(),
4041
});
4142

42-
const beginOAuthFlow = z.object({
43-
redirect_uri: z.url({
44-
// Only accept internal/private/local IP addresses
45-
hostname:
46-
/(^localhost$)|(^0\.0\.0\.0$)|(^127\.)|(^192\.168\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/i,
43+
const beginOAuthFlow = z.union([
44+
z.object({
45+
redirect_uri: z.url({
46+
// Only accept internal/private/local IP addresses
47+
hostname:
48+
/(^localhost$)|(^0\.0\.0\.0$)|(^127\.)|(^192\.168\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/i,
49+
}),
50+
client_id: z.string(),
51+
state: z.string().optional(),
4752
}),
48-
client_id: z.string(),
49-
state: z.string().optional(),
50-
});
53+
z.object({
54+
redirect_uri: z.url({
55+
hostname: /devdogsuga.org$/i,
56+
}),
57+
client_id: z.literal(env.SHARED_AUTH_CLIENT_ID!),
58+
state: z.string().optional(),
59+
}),
60+
]);
5161

5262
export const searchParamsSchema = z
5363
.instanceof(URLSearchParams)

0 commit comments

Comments
 (0)