diff --git a/forms/account-freemarker/src/main/java/org/keycloak/account/freemarker/model/TotpBean.java b/forms/account-freemarker/src/main/java/org/keycloak/account/freemarker/model/TotpBean.java index 419f3213e5..11363fa05b 100755 --- a/forms/account-freemarker/src/main/java/org/keycloak/account/freemarker/model/TotpBean.java +++ b/forms/account-freemarker/src/main/java/org/keycloak/account/freemarker/model/TotpBean.java @@ -41,11 +41,9 @@ public class TotpBean { private final String totpSecretEncoded; private final boolean enabled; private final String contextUrl; - private final String realmName; private final String keyUri; public TotpBean(KeycloakSession session, RealmModel realm, UserModel user, URI baseUri) { - this.realmName = realm.getName(); this.enabled = session.users().configuredForCredentialType(realm.getOTPPolicy().getType(), realm, user); this.contextUrl = baseUri.getPath(); diff --git a/forms/login-freemarker/src/main/java/org/keycloak/login/freemarker/model/TotpBean.java b/forms/login-freemarker/src/main/java/org/keycloak/login/freemarker/model/TotpBean.java index 6c9def495f..eae56dc39e 100755 --- a/forms/login-freemarker/src/main/java/org/keycloak/login/freemarker/model/TotpBean.java +++ b/forms/login-freemarker/src/main/java/org/keycloak/login/freemarker/model/TotpBean.java @@ -39,11 +39,9 @@ public class TotpBean { private final String totpSecretEncoded; private final boolean enabled; private final String contextUrl; - private final String realmName; private final String keyUri; public TotpBean(RealmModel realm, UserModel user, URI baseUri) { - this.realmName = realm.getName(); this.enabled = user.isOtpEnabled(); this.contextUrl = baseUri.getPath(); diff --git a/model/api/src/main/java/org/keycloak/models/OTPPolicy.java b/model/api/src/main/java/org/keycloak/models/OTPPolicy.java index 157842e94e..8d76bb9b83 100755 --- a/model/api/src/main/java/org/keycloak/models/OTPPolicy.java +++ b/model/api/src/main/java/org/keycloak/models/OTPPolicy.java @@ -97,8 +97,11 @@ public class OTPPolicy implements Serializable { public String getKeyURI(RealmModel realm, UserModel user, String secret) { + String displayName = realm.getDisplayName(); String uri = null; - uri = "otpauth://" + type + "/" + realm.getName() + ":" + user.getUsername() + "?secret=" + + + if (displayName == null || displayName.isEmpty()) { displayName = realm.getName(); } + uri = "otpauth://" + type + "/" + displayName + ":" + user.getUsername() + "?secret=" + Base32.encode(secret.getBytes()) + "&digits=" + digits + "&algorithm=" + algToKeyUriAlg.get(algorithm); try { uri += "&issuer=" + URLEncoder.encode(realm.getName(), "UTF-8");