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) {
|
||||||
|
try {
|
||||||
|
String displayName = realm.getDisplayName() != null && !realm.getDisplayName().isEmpty() ? realm.getDisplayName() : realm.getName();
|
||||||
|
String uri;
|
||||||
|
|
||||||
String displayName = realm.getDisplayName();
|
uri = "otpauth://" + type + "/" + URLEncoder.encode(user.getUsername(), "UTF-8") + "?secret=" +
|
||||||
String uri = null;
|
Base32.encode(secret.getBytes()) + "&digits=" + digits + "&algorithm=" + algToKeyUriAlg.get(algorithm);
|
||||||
|
|
||||||
if (displayName == null || displayName.isEmpty()) { displayName = realm.getName(); }
|
uri += "&issuer=" + URLEncoder.encode(displayName, "UTF-8");
|
||||||
uri = "otpauth://" + type + "/" + displayName + ":" + user.getUsername() + "?secret=" +
|
|
||||||
Base32.encode(secret.getBytes()) + "&digits=" + digits + "&algorithm=" + algToKeyUriAlg.get(algorithm);
|
if (type.equals(UserCredentialModel.HOTP)) {
|
||||||
try {
|
uri += "&counter=" + initialCounter;
|
||||||
uri += "&issuer=" + URLEncoder.encode(realm.getName(), "UTF-8");
|
}
|
||||||
} catch (UnsupportedEncodingException e) {
|
if (type.equals(UserCredentialModel.TOTP)) {
|
||||||
logger.debug("Failed to add issuer parameter to OTP URI becasue UTF-8 is not supported.");
|
uri += "&period=" + period;
|
||||||
}
|
}
|
||||||
if (type.equals(UserCredentialModel.HOTP)) {
|
|
||||||
uri += "&counter=" + initialCounter;
|
return uri;
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
if (type.equals(UserCredentialModel.TOTP)) {
|
|
||||||
uri += "&period=" + period;
|
|
||||||
}
|
|
||||||
return uri;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue