Skip to content

Commit

Permalink
Merge pull request #77 from edewit/added-pages
Browse files Browse the repository at this point in the history
Added some extra pages
  • Loading branch information
stianst authored Jul 18, 2024
2 parents 104bcaa + 6a559b6 commit 2e23be1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
4 changes: 2 additions & 2 deletions kc-ext/theme-preview/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ the realm configuration through a proxy.
At the moment it is only possible to alter realm configuration that returns Boolean or String
parameters, and take no arguments.

For example to enable user registration add `?registrationAllowed=true`, or to change the realm
display name set `?displayNameHtml=My realm`.
For example to enable user registration add `?realm.registrationAllowed=true`, or to change the realm
display name set `?realm.displayNameHtml=My realm`.

To view everything that can be altered take a look at [RealmModel.java](https://github.com/keycloak/keycloak/blob/main/server-spi/src/main/java/org/keycloak/models/RealmModel.java).
Anything that returns a boolean or a String and takes no arguments can be override. The query parameter name is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import org.keycloak.credential.CredentialInput;
import org.keycloak.credential.CredentialModel;
import org.keycloak.models.SubjectCredentialManager;
import org.keycloak.models.credential.RecoveryAuthnCodesCredentialModel;
import org.keycloak.models.utils.RecoveryAuthnCodesUtils;

import java.util.LinkedList;
import java.util.List;
import java.util.stream.Stream;

Expand Down Expand Up @@ -46,7 +47,13 @@ public Stream<CredentialModel> getStoredCredentialsStream() {

@Override
public Stream<CredentialModel> getStoredCredentialsByTypeStream(String s) {
return new LinkedList<CredentialModel>().stream();
List<String> generatedRecoveryAuthnCodes = RecoveryAuthnCodesUtils.generateRawCodes();
CredentialModel recoveryAuthnCodesCred = RecoveryAuthnCodesCredentialModel.createFromValues(
generatedRecoveryAuthnCodes,
System.currentTimeMillis(),
null);

return Stream.of(recoveryAuthnCodesCred);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package org.keycloak.ext.theme;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.keycloak.forms.login.LoginFormsProvider;
Expand All @@ -24,8 +20,11 @@ public class ThemePreviewProvider implements RealmResourceProvider {
new Page("login", "Login - username and password", LoginFormsProvider::createLoginUsernamePassword),
new Page("login-username", "Login - username", LoginFormsProvider::createLoginUsername),
new Page("login-otp", "Login - OTP", LoginFormsProvider::createLoginTotp),
new Page("login-recovery-codes", "Login - recovery codes", LoginFormsProvider::createLoginRecoveryAuthnCode),
new Page("login-config-recover-codes", "Action - recovery codes", l -> l.createResponse(UserModel.RequiredAction.CONFIGURE_RECOVERY_AUTHN_CODES)),
new Page("login-config-totp", "Action - OTP", l -> l.createResponse(UserModel.RequiredAction.CONFIGURE_TOTP)),
new Page("login-update-password", "Action - Update password", l -> l.createResponse(UserModel.RequiredAction.UPDATE_PASSWORD))
new Page("login-update-password", "Action - Update password", l -> l.createResponse(UserModel.RequiredAction.UPDATE_PASSWORD)),
new Page("login-register", "Action - Register", LoginFormsProvider::createRegistration)
);

private KeycloakSession session;
Expand All @@ -48,7 +47,7 @@ public Response list() {
sb.append("<ul>\n");

for (Page p : pages) {
sb.append("<li><a href=\"" + p.template + "\">" + p.description + "</a></li>\n");
sb.append("<li><a href=\"%s\">%s</a></li>\n".formatted(p.template, p.description));
}

sb.append("</ul>\n");
Expand Down

0 comments on commit 2e23be1

Please sign in to comment.