Im a ROR/JS FSD and a newbie to Java and Keycloak, Im setting up an auth server to be used by multiple rails applications and need to extend the functionality with a one time token endpoint. Im running Keycloak v20.0.1 on a docker image and trying to deploy a custom REST spi
I have a keycloack_basic_action_token_spi package, in the package I have
AcionTokenProvider.java
package extension.keycloak.resource;
import ...
@RequiredArgsConstructor
public class ActionTokenProvider implements RealmResourceProvider {
private final KeycloakSession session;
@Context
UriInfo uriInfo;
@Override
public Object getResource() {
return this;
}
@Override
public void close() {
}
@POST
@Path("generate-action-token")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response getActionToken(@FormParam("user-id") String userId,
@FormParam("exp-in-seconds") int absoluteExpirationInSecs,
@FormParam("session-id") String authenticationSessionId,
@Context UriInfo uriInfo) {
KeycloakContext context = session.getContext();
final AuthenticationSessionModel authSession = context.getAuthenticationSession();
final String clientId = "account";
String actionToken = new OneTimeActionToken(
userId,
1800,
clientId
).serialize(
session,
context.getRealm(),
uriInfo
);
return Response.ok(Map.of(TOKEN_TYPE, actionToken)).build();
}
}
AcionTokenProvider.java
package extension.keycloak.resource;
import ...
public class ActionTokenProviderFactory implements RealmResourceProviderFactory {
public static final String PROVIDER_ID = "action-token-rest-resource";
@Override
public RealmResourceProvider create(KeycloakSession keycloakSession) {
return new ActionTokenProvider(keycloakSession);
}
@Override
public void init(Config.Scope scope) {
}
@Override
public void postInit(KeycloakSessionFactory keycloakSessionFactory) {
}
@Override
public void close() {
}
@Override
public String getId() {
return PROVIDER_ID;
}
}
and in resources/META-INF/services/org.keycloak.services.resource.RealmResourceProviderFactory
extension.keycloak.resource.ActionTokenProviderFactory
since I'm running keycloak on a docker image Im compiling and copying my jar file to my image with
mvn package && docker cp target/extension.keycloak-keycloak-basic-action-token.jar keycloak:/./opt/keycloak/providers
and from the image I'm able to run bin/kc.sh build
from the Keycloak directory and getting
Updating the configuration and installing your custom providers, if any. Please wait.
2022-11-24 17:49:08,994 WARN [org.keycloak.services] (build-10) KC-SERVICES0047: action-token-rest-resource (extension.keycloak.resource.ActionTokenProviderFactory) is implementing the internal SPI realm-restapi-extension. This SPI is internal and may change without notice
2022-11-24 17:49:08,995 WARN [org.keycloak.services] (build-10) KC-SERVICES0047: my-rest-resource (sample.keycloak.resource.MyResourceProviderFactory) is implementing the internal SPI realm-restapi-extension. This SPI is internal and may change without notice
2022-11-24 17:49:14,622 INFO [io.quarkus.deployment.QuarkusAugmentor] (main) Quarkus augmentation completed in 8822ms
Server configuration updated and persisted. Run the following command to review the configuration:
kc.sh show-config
Everything seems to build alright and Im able to restart my keycloak instance just fine however when I try to curl my new end point I get a 404. Im not sure what am I missing here.