mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-26 14:28:46 +00:00
fix(login): forward login_hint to the external IdP (#12760)
# Which Problems Are Solved Login V2 never forwards the OIDC `login_hint` to an external identity provider. The user enters their identifier once at ZITADEL, is redirected to the IdP, and has to type it again because the IdP's authorize request contains no `login_hint`. Login V1 has done this since #6899 (`sessionParamsFromAuthRequest`), and the backend half for V2 exists since #11552 (`RedirectURLs.login_hint` on `StartIdentityProviderIntent`), but none of the three places in the login app that start an IdP intent set it. # How the Problems Are Solved Every call to `startIdentityProviderFlow` now sets `urls.loginHint`, mirroring the priority Login V1 uses: - `sendLoginname`: when the user is already known and linked to exactly one IdP, the hint is the username the IdP knows the user by (`IDPLink.userName`), falling back to the typed login name (with the org domain suffix re-attached). When an org's single active IdP triggers the redirect, the hint is the login name. - `handleOIDCFlowInitiation`: when the auth request selects an IdP via `urn:zitadel:iam:org:idp🆔<id>`, the hint is `authRequest.loginHint`. - `redirectToIdp` (the user clicks an IdP button): `SignInWithIdp` gets an optional `loginHint` prop rendered as a hidden form field. The loginname page passes the login name it was prefilled with from `login_hint`; the authenticator setup page passes the session's login name when linking an IdP to an existing user. Unit tests cover all three call sites, including the linked-username priority and the empty-hint case. Closes #12080 Based on #12683 by @aarontraynor
This commit is contained in:
@@ -35,6 +35,7 @@ export async function redirectToIdp(prevState: RedirectToIdpState, formData: For
|
||||
const idpId = formData.get("id") as string;
|
||||
const provider = formData.get("provider") as string;
|
||||
const postErrorRedirectUrl = formData.get("postErrorRedirectUrl") as string;
|
||||
const loginHint = formData.get("loginHint") as string;
|
||||
|
||||
if (sessionId) {
|
||||
try {
|
||||
@@ -72,6 +73,7 @@ export async function redirectToIdp(prevState: RedirectToIdpState, formData: For
|
||||
idpId,
|
||||
successUrl: `/idp/${provider}/process?` + params.toString(),
|
||||
failureUrl: `/idp/${provider}/failure?` + params.toString(),
|
||||
loginHint: loginHint || undefined,
|
||||
});
|
||||
|
||||
if (!response) {
|
||||
@@ -99,6 +101,7 @@ export type StartIDPFlowCommand = {
|
||||
idpId: string;
|
||||
successUrl: string;
|
||||
failureUrl: string;
|
||||
loginHint?: string;
|
||||
};
|
||||
|
||||
async function startIDPFlow(command: StartIDPFlowCommand) {
|
||||
@@ -110,6 +113,7 @@ async function startIDPFlow(command: StartIDPFlowCommand) {
|
||||
urls: {
|
||||
successUrl: `${command.host.includes("localhost") ? "http://" : "https://"}${command.host}${basePath}${command.successUrl}`,
|
||||
failureUrl: `${command.host.includes("localhost") ? "http://" : "https://"}${command.host}${basePath}${command.failureUrl}`,
|
||||
loginHint: command.loginHint,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user