KEYCLOAK-2410
TOTP shows both realm name and display name
This commit is contained in:
parent
9f2bd0f55e
commit
9bd04b18a8
1 changed files with 17 additions and 17 deletions
|
@ -96,25 +96,25 @@ public class OTPPolicy implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getKeyURI(RealmModel realm, UserModel user, String secret) {
|
public String getKeyURI(RealmModel realm, UserModel user, String secret) {
|
||||||
|
|
||||||
String displayName = realm.getDisplayName();
|
|
||||||
String uri = null;
|
|
||||||
|
|
||||||
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 {
|
try {
|
||||||
uri += "&issuer=" + URLEncoder.encode(realm.getName(), "UTF-8");
|
String displayName = realm.getDisplayName() != null && !realm.getDisplayName().isEmpty() ? realm.getDisplayName() : realm.getName();
|
||||||
} catch (UnsupportedEncodingException e) {
|
String uri;
|
||||||
logger.debug("Failed to add issuer parameter to OTP URI becasue UTF-8 is not supported.");
|
|
||||||
}
|
uri = "otpauth://" + type + "/" + URLEncoder.encode(user.getUsername(), "UTF-8") + "?secret=" +
|
||||||
|
Base32.encode(secret.getBytes()) + "&digits=" + digits + "&algorithm=" + algToKeyUriAlg.get(algorithm);
|
||||||
|
|
||||||
|
uri += "&issuer=" + URLEncoder.encode(displayName, "UTF-8");
|
||||||
|
|
||||||
if (type.equals(UserCredentialModel.HOTP)) {
|
if (type.equals(UserCredentialModel.HOTP)) {
|
||||||
uri += "&counter=" + initialCounter;
|
uri += "&counter=" + initialCounter;
|
||||||
}
|
}
|
||||||
if (type.equals(UserCredentialModel.TOTP)) {
|
if (type.equals(UserCredentialModel.TOTP)) {
|
||||||
uri += "&period=" + period;
|
uri += "&period=" + period;
|
||||||
}
|
}
|
||||||
return uri;
|
|
||||||
|
|
||||||
|
return uri;
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue