Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no result to parse on success #27985

Merged
merged 1 commit into from Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion js/apps/account-ui/src/account-security/AccountRow.tsx
Expand Up @@ -22,7 +22,11 @@ type AccountRowProps = {
refresh: () => void;
};

export const AccountRow = ({ account, isLinked = false }: AccountRowProps) => {
export const AccountRow = ({
account,
isLinked = false,
refresh,
}: AccountRowProps) => {
const { t } = useTranslation();
const context = useEnvironment();
const { addAlert, addError } = useAlerts();
Expand All @@ -31,6 +35,7 @@ export const AccountRow = ({ account, isLinked = false }: AccountRowProps) => {
try {
await unLinkAccount(context, account);
addAlert(t("unLinkSuccess"));
refresh();
} catch (error) {
addError(t("unLinkError", { error }).toString());
}
Expand Down
1 change: 1 addition & 0 deletions js/apps/account-ui/src/api/methods.ts
Expand Up @@ -124,6 +124,7 @@ export async function unLinkAccount(
method: "DELETE",
},
);
if (response.ok) return;
return parseResponse(response);
}

Expand Down
Expand Up @@ -16,6 +16,7 @@
*/
package org.keycloak.services.resources.account;

import java.io.IOException;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
Expand Down Expand Up @@ -60,6 +61,7 @@
import org.keycloak.services.managers.Auth;
import org.keycloak.services.messages.Messages;
import org.keycloak.services.validation.Validation;
import org.keycloak.theme.Theme;

import static org.keycloak.models.Constants.ACCOUNT_CONSOLE_CLIENT_ID;

Expand Down Expand Up @@ -201,12 +203,12 @@ public Response removeLinkedAccount(@PathParam("providerAlias") String providerA

FederatedIdentityModel link = session.users().getFederatedIdentity(realm, user, providerAlias);
if (link == null) {
throw ErrorResponse.error(Messages.FEDERATED_IDENTITY_NOT_ACTIVE, Response.Status.BAD_REQUEST);
throw ErrorResponse.error(translateErrorMessage(Messages.FEDERATED_IDENTITY_NOT_ACTIVE), Response.Status.BAD_REQUEST);
}

// Removing last social provider is not possible if you don't have other possibility to authenticate
if (!(session.users().getFederatedIdentitiesStream(realm, user).count() > 1 || user.getFederationLink() != null || isPasswordSet())) {
throw ErrorResponse.error(Messages.FEDERATED_IDENTITY_REMOVING_LAST_PROVIDER, Response.Status.BAD_REQUEST);
throw ErrorResponse.error(translateErrorMessage(Messages.FEDERATED_IDENTITY_REMOVING_LAST_PROVIDER), Response.Status.BAD_REQUEST);
}

session.users().removeFederatedIdentity(realm, user, providerAlias);
Expand Down Expand Up @@ -239,6 +241,14 @@ private String checkCommonPreconditions(String providerAlias) {

return null;
}

private String translateErrorMessage(String errorCode) {
try {
return session.theme().getTheme(Theme.Type.ACCOUNT).getMessages(session.getContext().resolveLocale(user)).getProperty(errorCode);
} catch (IOException e) {
return errorCode;
}
}

private boolean isPasswordSet() {
return user.credentialManager().isConfiguredFor(PasswordCredentialModel.TYPE);
Expand Down