mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-11 00:25:12 +00:00
fix(user): Updating user info when authenticating with external IDP (#11046)
# Which Problems Are Solved User profile updates were not propagated when using External OIDC IDP + Login V2 # How the Problems Are Solved * `UpdateHumanUserRequest` is added to `RetrieveIdentityProviderIntentResponse` * `UpdateHumanUserRequest` is returned in the `RetrieveIdentityProviderIntentResponse` when the user already exists during external IDP auth, which is then used in the frontend to update the user info # Additional Changes * Moved integration tests related to user intent to a separate test file * Fix redirection after external IDP user registration # Additional Context - Closes #10838 - Follow up: https://github.com/zitadel/zitadel/issues/11053 --------- Co-authored-by: Max Peintner <[email protected]>
This commit is contained in:
co-authored by
Max Peintner
parent
a3390a0adb
commit
d7e9eddb76
@@ -4,6 +4,7 @@ import { registerUserAndLinkToIDP } from "@/lib/server/register";
|
||||
import { useState } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { FieldValues, useForm } from "react-hook-form";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { Alert } from "./alert";
|
||||
import { BackButton } from "./back-button";
|
||||
import { Button, ButtonVariants } from "./button";
|
||||
@@ -55,6 +56,7 @@ export function RegisterFormIDPIncomplete({
|
||||
});
|
||||
|
||||
const t = useTranslations("register");
|
||||
const router = useRouter();
|
||||
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
const [error, setError] = useState<string>("");
|
||||
@@ -85,7 +87,9 @@ export function RegisterFormIDPIncomplete({
|
||||
return;
|
||||
}
|
||||
|
||||
// If no error, the function has already handled the redirect
|
||||
if (response && "redirect" in response && response.redirect) {
|
||||
return router.push(response.redirect);
|
||||
}
|
||||
}
|
||||
|
||||
const { errors } = formState;
|
||||
|
||||
@@ -76,6 +76,17 @@ describe("processIDPCallback", () => {
|
||||
email: "[email protected]",
|
||||
},
|
||||
},
|
||||
updateHumanUser: {
|
||||
username: "testuser",
|
||||
profile: {
|
||||
givenName: "Test",
|
||||
familyName: "User 1",
|
||||
displayName: "Test User 1",
|
||||
},
|
||||
email: {
|
||||
email: "[email protected]",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const defaultIdp = {
|
||||
@@ -257,8 +268,8 @@ describe("processIDPCallback", () => {
|
||||
serviceUrl: "https://api.example.com",
|
||||
request: expect.objectContaining({
|
||||
userId: "user123",
|
||||
profile: defaultIntent.addHumanUser.profile,
|
||||
email: defaultIntent.addHumanUser.email,
|
||||
profile: defaultIntent.updateHumanUser.profile,
|
||||
email: defaultIntent.updateHumanUser.email,
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
@@ -119,7 +119,7 @@ export async function processIDPCallback({
|
||||
|
||||
console.log("[IDP Process] Intent retrieved successfully, processing business logic");
|
||||
|
||||
const { idpInformation, userId, addHumanUser } = intent;
|
||||
const { idpInformation, userId, addHumanUser, updateHumanUser } = intent;
|
||||
|
||||
if (!idpInformation) {
|
||||
console.error("[IDP Process] IDP information missing");
|
||||
@@ -161,15 +161,15 @@ export async function processIDPCallback({
|
||||
// ============================================
|
||||
if (userId && !link) {
|
||||
// Auto-update user if enabled
|
||||
if (options?.isAutoUpdate && addHumanUser) {
|
||||
if (options?.isAutoUpdate && updateHumanUser) {
|
||||
try {
|
||||
await updateHuman({
|
||||
serviceUrl,
|
||||
request: create(UpdateHumanUserRequestSchema, {
|
||||
userId: userId,
|
||||
profile: addHumanUser.profile,
|
||||
email: addHumanUser.email,
|
||||
phone: addHumanUser.phone,
|
||||
profile: updateHumanUser.profile,
|
||||
email: updateHumanUser.email,
|
||||
phone: updateHumanUser.phone,
|
||||
}),
|
||||
});
|
||||
console.log("[IDP Process] User auto-updated successfully");
|
||||
|
||||
Reference in New Issue
Block a user