Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[Issue#1068] KeycloakApi doesn't work with Keycloak version >= 17
  • Loading branch information
cgs-jfpollender committed Mar 21, 2024
commit d9c12fc572b922b08bca4c7b57789ff1a01097a3
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.github.scribejava.core.builder.api.DefaultApi20;
import com.github.scribejava.core.extractors.TokenExtractor;
import com.github.scribejava.core.model.OAuth2AccessToken;
import com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication;
import com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
Expand Down Expand Up @@ -38,7 +40,7 @@ public static KeycloakApi instance(String baseUrl, String realm) {
}

protected static String composeBaseUrlWithRealm(String baseUrl, String realm) {
return baseUrl + (baseUrl.endsWith("/") ? "" : "/") + "auth/realms/" + realm;
return baseUrl + (baseUrl.endsWith("/") ? "" : "/") + "realms/" + realm;
}

@Override
Expand All @@ -51,6 +53,11 @@ protected String getAuthorizationBaseUrl() {
return baseUrlWithRealm + "/protocol/openid-connect/auth";
}

@Override
public ClientAuthentication getClientAuthentication() {
return RequestBodyAuthenticationScheme.instance();
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this change required?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is required. I will remove it


@Override
public TokenExtractor<OAuth2AccessToken> getAccessTokenExtractor() {
return OpenIdJsonTokenExtractor.instance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public static void main(String... args) throws IOException, InterruptedException
final String apiKey = "your_api_key";
final String apiSecret = "your_api_secret";
final String callback = "your_callback";
final String baseUrl = "your_base_url";
final String baseUrl = "your_base_url"; // Add /auth at the end when using keycloak version < 17
final String realm = "your_realm";

final String protectedResourceUrl = baseUrl + "/auth/realms/" + realm + "/protocol/openid-connect/userinfo";
final String protectedResourceUrl = baseUrl + "/realms/" + realm + "/protocol/openid-connect/userinfo";

final OAuth20Service service = new ServiceBuilder(apiKey)
.apiSecret(apiSecret)
Expand Down