Skip to content

fixing path segments for keycloak 21.0.1 #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public String authorizationServerUrl(String callbackUrl) throws Exception {

return HttpUrl.parse(keycloakConfiguration.keycloakEndpoint())
.newBuilder()
.addPathSegments("auth")
.addPathSegments("realms")
.addPathSegments(realm)
.addPathSegments("protocol")
Expand All @@ -86,7 +85,6 @@ public TokenInfo fetchAccessToken(Map<String, String> params) throws Exception {

final String accessTokenUrl = HttpUrl.parse(keycloakConfiguration.keycloakEndpoint())
.newBuilder()
.addPathSegments("auth")
.addPathSegments("realms")
.addPathSegments(realm)
.addPathSegments("protocol")
Expand Down Expand Up @@ -118,7 +116,6 @@ public KeycloakUser userProfile(TokenInfo tokenInfo) throws Exception {

final String userProfileUrl = HttpUrl.parse(keycloakConfiguration.keycloakEndpoint())
.newBuilder()
.addPathSegments("auth")
.addPathSegments("realms")
.addPathSegments(realm)
.addPathSegments("protocol")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void tearDown() throws Exception {
public void shouldReturnAuthorizationServerUrl() throws Exception {
final String authorizationServerUrl = KeycloakApiClient.authorizationServerUrl("call-back-url");

assertThat(authorizationServerUrl, startsWith("https://example.com/auth/realms/master/protocol/openid-connect/auth?client_id=client-id&redirect_uri=call-back-url&response_type=code&scope=openid%20profile%20email%20roles&state="));
assertThat(authorizationServerUrl, startsWith("https://example.com/realms/master/protocol/openid-connect/auth?client_id=client-id&redirect_uri=call-back-url&response_type=code&scope=openid%20profile%20email%20roles&state="));
}

@Test
Expand All @@ -89,7 +89,7 @@ public void shouldFetchTokenInfoUsingAuthorizationCode() throws Exception {
assertThat(tokenInfo.accessToken(), is("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9"));

RecordedRequest request = server.takeRequest();
assertEquals("POST /auth/realms/master/protocol/openid-connect/token HTTP/1.1", request.getRequestLine());
assertEquals("POST /realms/master/protocol/openid-connect/token HTTP/1.1", request.getRequestLine());
assertEquals("application/x-www-form-urlencoded", request.getHeader("Content-Type"));
assertEquals("client_id=client-id&client_secret=client-secret&code=some-code&grant_type=authorization_code&redirect_uri=callback-url", request.getBody().readUtf8());
}
Expand All @@ -108,7 +108,7 @@ public void shouldFetchUserProfile() throws Exception {
assertThat(KeycloakUser.getEmail(), is("[email protected]"));

RecordedRequest request = server.takeRequest();
assertEquals("GET /auth/realms/master/protocol/openid-connect/userinfo HTTP/1.1", request.getRequestLine());
assertEquals("GET /realms/master/protocol/openid-connect/userinfo HTTP/1.1", request.getRequestLine());
assertEquals("Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9", request.getHeader("Authorization"));
}

Expand All @@ -121,7 +121,7 @@ public void shouldErrorOutWhenAPIRequestFails() throws Exception {
when(KeycloakConfiguration.keycloakEndpoint()).thenReturn(server.url("/").toString());

thrown.expect(RuntimeException.class);
thrown.expectMessage("Api call to `/auth/realms/master/protocol/openid-connect/userinfo` failed with error: `Unauthorized`");
thrown.expectMessage("Api call to `/realms/master/protocol/openid-connect/userinfo` failed with error: `Unauthorized`");

KeycloakApiClient.userProfile(tokenInfo);
}
Expand Down