Skip to content

Commit 48359eb

Browse files
committed
feat: add clientServiceAccountUuid to connection-info endpoint
This allows the client to get the user account of the current client
1 parent 64fa2c0 commit 48359eb

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,14 @@ Required roles: `hawk-view-cache-buster`
184184
`/realms/{realm}/hawk/connection-info`
185185

186186
This endpoint returns information about the connection to the keycloak server required
187-
for a smooth client experience.
187+
for a smooth client experience. Note, to use this endpoint the requesting client MUST have a service account.
188188

189189
The response contains the following fields:
190190
* keycloakVersion - The version of the keycloak server (Used for compatibility checks on the client side)
191191
* extensionVersion - The version of the hawk keycloak extension
192192
* clientId - The client id of the client that requested the endpoint
193193
* clientUuid - The uuid of the client that requested the endpoint
194+
* clientServiceAccountUuid - The uuid of the service account of the client that requested the endpoint
194195

195196
Required roles `hawk-client`
196197

src/main/java/com/hawk/keycloak/util/ConnectionInfoRequestHandler.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.hawk.keycloak.util.model.ConnectionInfo;
55
import lombok.RequiredArgsConstructor;
66
import org.keycloak.common.Version;
7+
import org.keycloak.models.ClientModel;
78
import org.keycloak.models.KeycloakSession;
89

910
@RequiredArgsConstructor
@@ -14,11 +15,18 @@ public class ConnectionInfoRequestHandler {
1415
public ConnectionInfo handleRequest() {
1516
auth.requireHawkClientRole();
1617

18+
ClientModel client = session.getContext().getClient();
19+
20+
if(!client.isServiceAccountsEnabled()){
21+
throw new RuntimeException("Service accounts are not enabled for this client, but this is required for the clients to work well");
22+
}
23+
1724
return new ConnectionInfo(
1825
Version.VERSION,
1926
VersionInfo.getPackageVersion(),
20-
session.getContext().getClient().getClientId(),
21-
session.getContext().getClient().getId()
27+
client.getClientId(),
28+
client.getId(),
29+
session.users().getServiceAccount(client).getId()
2230
);
2331
}
2432
}

src/main/java/com/hawk/keycloak/util/model/ConnectionInfo.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ public class ConnectionInfo {
1010
private final String extensionVersion;
1111
private final String clientId;
1212
private final String clientUuid;
13+
private final String clientServiceAccountUuid;
1314
}

0 commit comments

Comments
 (0)