@@ -12,7 +12,7 @@ import org.apache.pekko.http.scaladsl.server.{AuthenticationFailedRejection, Dir
12
12
import org .apache .pekko .http .scaladsl .unmarshalling .Unmarshal
13
13
import org .keycloak .TokenVerifier
14
14
import org .keycloak .adapters .KeycloakDeploymentBuilder
15
- import org .keycloak .admin .client .{CreatedResponseUtil , Keycloak , KeycloakBuilder }
15
+ import org .keycloak .admin .client .{CreatedResponseUtil , Keycloak }
16
16
import org .keycloak .jose .jws .AlgorithmType
17
17
import org .keycloak .representations .AccessToken
18
18
import org .keycloak .representations .adapters .config .AdapterConfig
@@ -33,13 +33,13 @@ import scala.util.{Failure, Success}
33
33
34
34
35
35
/**
36
- * A "one-click" Keycloak OIDC server with pekko-http frontend
36
+ * A "one-click" Keycloak OIDC server with pekko-http frontend.
37
+ * The pekko-http endpoint /users loads all users from the Keycloak server.
37
38
*
38
39
* Inspired by:
39
40
* https://scalac.io/blog/user-authentication-keycloak-1
40
41
*
41
- * Uses a HTML5 client:
42
- * https://github.com/keycloak/keycloak/tree/main/examples/js-console
42
+ * Uses a HTML5 client: src/main/resources/KeycloakClient.html
43
43
* instead of the separate React client
44
44
*
45
45
* Runs with:
@@ -48,8 +48,7 @@ import scala.util.{Failure, Success}
48
48
*
49
49
* Doc:
50
50
* https://www.keycloak.org/docs/latest/securing_apps/#_javascript_adapter
51
- * https://doc.akka.io/docs/akka-http/current/routing-dsl/directives/security-directives/index.html
52
- *
51
+ * https://pekko.apache.org/docs/pekko-http/1.0/routing-dsl/directives/security-directives/index.html
53
52
*/
54
53
object OIDCKeycloak extends App with CORSHandler with JsonSupport {
55
54
val logger : Logger = LoggerFactory .getLogger(this .getClass)
@@ -59,7 +58,7 @@ object OIDCKeycloak extends App with CORSHandler with JsonSupport {
59
58
60
59
def runKeycloak () = {
61
60
// Pin to same version as "keycloakVersion" in build.sbt
62
- val keycloak = new KeycloakContainer (" quay.io/keycloak/keycloak:21.1.2 " )
61
+ val keycloak = new KeycloakContainer (" quay.io/keycloak/keycloak:24.0.4 " )
63
62
// Keycloak config taken from:
64
63
// https://github.com/keycloak/keycloak/blob/main/examples/js-console/example-realm.json
65
64
.withRealmImportFile(" keycloak_realm_config.json" )
@@ -74,14 +73,8 @@ object OIDCKeycloak extends App with CORSHandler with JsonSupport {
74
73
val adminClientId = " admin-cli"
75
74
76
75
def initAdminClient () = {
77
- val keycloakAdminClient = KeycloakBuilder .builder()
78
- .serverUrl(keycloak.getAuthServerUrl)
79
- .realm(" master" )
80
- .clientId(adminClientId)
81
- .username(keycloak.getAdminUsername)
82
- .password(keycloak.getAdminPassword)
83
- .build()
84
- logger.info(" Connected to Keycloak server version: " + keycloakAdminClient.serverInfo().getInfo.getSystemInfo.getVersion)
76
+ val keycloakAdminClient = keycloak.getKeycloakAdminClient()
77
+ logger.info(" Connected to Keycloak server version: {}" , keycloakAdminClient.serverInfo().getInfo.getSystemInfo.getVersion)
85
78
keycloakAdminClient
86
79
}
87
80
0 commit comments