Skip to content

Commit 45b279f

Browse files
committed
🕸️
1 parent d2d4553 commit 45b279f

File tree

7 files changed

+22
-16
lines changed

7 files changed

+22
-16
lines changed

app1/ui/components/ProfileImage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export default function ProfileImage(props: {
8888
return_url: "https://app.example.local/app1",
8989
});
9090

91-
window.location.href = `https://auth.example.local/auth/signin/portal?${params}`;
91+
window.location.href = `https://auth.example.local/auth/signin/zitadel?${params}`;
9292
}}
9393
>
9494
+ Add other account
@@ -109,7 +109,7 @@ export default function ProfileImage(props: {
109109
params.set("id_token_hint", session.idToken);
110110
}
111111

112-
window.location.href = `https://auth.example.local/auth/signout/portal?${params}`;
112+
window.location.href = `https://auth.example.local/auth/signout/zitadel?${params}`;
113113
}}
114114
>
115115
Logout

app2/ui/Home.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default function Home() {
3737
return_url: "https://app.example.local/app2",
3838
});
3939

40-
window.location.href = `https://auth.example.local/auth/signin/zitadel?${params}`;
40+
window.location.href = `https://auth.example.local/auth/signin/portal?${params}`;
4141
}}
4242
>
4343
Login
@@ -52,7 +52,7 @@ export default function Home() {
5252
params.set("id_token_hint", sessions[0].idToken);
5353
}
5454

55-
window.location.href = `https://auth.example.local/auth/signout/zitadel?${params}`;
55+
window.location.href = `https://auth.example.local/auth/signout/portal?${params}`;
5656
}}
5757
>
5858
Logout

auth/app/api/auth/callback/[provider]/route.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ async function handler(
2121
try {
2222
const code = request.nextUrl.searchParams.get("code");
2323
const state = request.nextUrl.searchParams.get("state");
24+
const provider = params.provider;
25+
if (!provider) throw new Error("provider not found");
2426

2527
const requestCookie = cookies();
2628
const returnUrlCookie = requestCookie.get(returnUrlCookieName);
@@ -36,17 +38,14 @@ async function handler(
3638
if (stateCookie.value !== state) throw new Error("Invalid state");
3739

3840
if (!redirectCookie) throw new Error("Redirect url cookie not found");
39-
if (redirectCookie.value !== configuration.redirectUrl)
41+
if (redirectCookie.value !== configuration[provider].redirectUrl)
4042
throw new Error("Invalid redirect url");
4143

42-
const provider = params.provider;
43-
if (!provider) throw new Error("provider not found");
44-
4544
const tokenParams = new URLSearchParams();
4645
tokenParams.append("code", code as string);
4746
tokenParams.append("grant_type", "authorization_code");
4847
tokenParams.append("client_id", configuration[provider].clientId);
49-
tokenParams.append("redirect_uri", configuration.redirectUrl);
48+
tokenParams.append("redirect_uri", configuration[provider].redirectUrl);
5049
tokenParams.append("code_verifier", codeVerifierCookie.value);
5150

5251
const wellKnownResponse = await fetch(

auth/app/api/auth/signin/[provider]/route.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export async function POST(
6262
code_challenge: codeChallenge,
6363
code_challenge_method: "S256",
6464
client_id: configuration[provider].clientId,
65-
redirect_uri: configuration.redirectUrl,
65+
redirect_uri: configuration[provider].redirectUrl,
6666
response_type: "code",
6767
scope,
6868
state,
@@ -73,10 +73,13 @@ export async function POST(
7373

7474
if (returnUrl) setShortLiveCookie(returnUrlCookieName, returnUrl);
7575
setShortLiveCookie(stateCookieName, state);
76-
setShortLiveCookie(redirectUrlCookieName, configuration.redirectUrl);
76+
setShortLiveCookie(
77+
redirectUrlCookieName,
78+
configuration[provider].redirectUrl
79+
);
7780
setShortLiveCookie(codeVerifierCookieName, codeVerifier);
7881
deleteCookie(csrfTokenCookieName);
7982

80-
const authorizeUrl = `${wellKnown.authorization_endpoint}?${params}`;
83+
const authorizeUrl = `${wellKnown.authorization_endpoint}?${requestParams}`;
8184
return NextResponse.json({ authorizeUrl });
8285
}

auth/app/api/auth/signout/[provider]/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export async function POST(
6969

7070
if (returnUrl) setShortLiveCookie(returnUrlCookieName, returnUrl);
7171

72-
const endSessionUrl = `${wellKnown.end_session_endpoint}?${params}`;
72+
const endSessionUrl = `${wellKnown.end_session_endpoint}?${requestParams}`;
7373

7474
return NextResponse.json({ endSessionUrl });
7575
} catch (error: any) {

auth/configuration.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,19 @@ const schema = z.object({
2424
portal: z.object({
2525
clientId: z.string(),
2626
issuer: z.string(),
27+
redirectUrl: z.string(),
2728
}),
2829
zitadel: z.object({
2930
clientId: z.string(),
31+
redirectUrl: z.string(),
3032
issuer: z.string(),
3133
}),
32-
redirectUrl: z.string(),
3334
postLogoutRedirectUri: z.string(),
3435
});
3536

36-
const configuration = {
37+
type Configuration = z.infer<typeof schema>;
38+
39+
const configuration: Configuration = {
3740
appUrl: "https://auth.example.local",
3841
domain: "example.local",
3942
originRegex: /^(.*\.)?(example\.local|real-domain\.com)$/,
@@ -44,12 +47,13 @@ const configuration = {
4447
portal: {
4548
issuer: "https://zitadel-login-ui-v2.vercel.app",
4649
clientId: "279716137237868517",
50+
redirectUrl: "https://auth.example.local/api/auth/callback/portal",
4751
},
4852
zitadel: {
4953
issuer: "https://system-v1-fpms4l.zitadel.cloud",
5054
clientId: "279716137237868517",
55+
redirectUrl: "https://auth.example.local/api/auth/callback/zitadel",
5156
},
52-
redirectUrl: "https://auth.example.local/api/auth/callback",
5357
postLogoutRedirectUri: "https://auth.example.local/auth/signedout",
5458
};
5559

auth/prisma/dev.db

4 KB
Binary file not shown.

0 commit comments

Comments
 (0)