keycloak-scim/examples/providers/domain-extension
2021-05-06 14:55:01 +02:00
..
src/main KEYCLOAK-15270 Account REST API doesn't verify audience 2020-09-14 08:43:09 -03:00
invoke-authenticated.sh KEYCLOAK-2474 Polishing. Support for separate changelock table per changelog. Support for authenticated endpoint in domain-extension example 2016-06-21 12:06:22 +02:00
pom.xml Set version to 14.0.0-SNAPSHOT 2021-05-06 14:55:01 +02:00
README.md KEYCLOAK-3882 Split server-spi into server-spi and server-spi-private 2016-11-10 13:28:42 +01:00

Example Domain Extension

To run, deploy as a module by running:

$KEYCLOAK_HOME/bin/jboss-cli.sh --command="module add --name=org.keycloak.examples.domain-extension-example --resources=target/domain-extension-example.jar --dependencies=org.keycloak.keycloak-core,org.keycloak.keycloak-services,org.keycloak.keycloak-model-jpa,org.keycloak.keycloak-server-spi,org.keycloak.keycloak-server-spi-private,javax.ws.rs.api,javax.persistence.api,org.hibernate,org.javassist,org.liquibase"

Then registering the provider by editing standalone/configuration/standalone.xml and adding the module to the providers element:

<providers>
    ...
    <provider>module:org.keycloak.examples.domain-extension-example</provider>
</providers>

Then start (or restart) the server.

Testing

First you can create some example companies with these CURL requests.

curl -i --request POST http://localhost:8080/auth/realms/master/example/companies --data "{ \"name\": \"foo company\" }" --header "Content-type: application/json"
curl -i --request POST http://localhost:8080/auth/realms/master/example/companies --data "{ \"name\": \"bar company\" }" --header "Content-type: application/json"

Then you can lookup all companies

curl -i --request GET http://localhost:8080/auth/realms/master/example/companies --header "Accept: application/json"

If you create realm foo in Keycloak admin console and then replace the realm name in the URI (for example like http://localhost:8080/auth/realms/foo/example/companies ) you will see that companies are scoped per-realm. So you will see different companies for realm master and for realm foo .

Testing with authenticated access

Example contains the endpoint, which is accessible just for authenticated users. REST request must be authenticated with bearer access token of authenticated user and the user must be in realm role admin in order to access the resource. You can run bash script from the current directory:

./invoke-authenticated.sh

The script assumes user admin with password admin exists in realm master. Also it assumes that you have curl installed.