Skip to content
Merged
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 @@ -99,7 +99,9 @@ public Response keycloakInitiatedBrowserLogout(
}

protected String getIdTokenForLogout(UserSessionModel userSession) {
return userSession.getNote(FEDERATED_ID_TOKEN);
// Since Keycloak 26.8 the note is suffixed with the provider alias
var idToken = userSession.getNote(FEDERATED_ID_TOKEN + ":" + getConfig().getAlias());
return idToken != null ? idToken : userSession.getNote(FEDERATED_ID_TOKEN);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.keycloak.models.KeyManager;
import org.keycloak.models.KeycloakContext;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.UserSessionModel;
import org.keycloak.representations.JsonWebToken;
import org.mockito.Mockito;

Expand Down Expand Up @@ -447,4 +448,34 @@ void should_throw_exception_when_id_token_contains_acr_claim_who_does_not_match_
.hasMessage("The returned eIDAS level cannot be retrieved");
}
}

@Nested
class IdTokenForLogout {

private FranceConnectIdentityProvider logoutProvider;
private UserSessionModel userSession;

@BeforeEach
void setup() {
var logoutConfig = givenConfigForIntegrationV1AndEidasLevel2();
logoutConfig.setAlias("franceconnect");
logoutProvider = new FranceConnectIdentityProvider(session, logoutConfig);
userSession = mock(UserSessionModel.class);
}

@Test
void should_read_the_id_token_note_suffixed_with_the_provider_alias() {
when(userSession.getNote("FEDERATED_ID_TOKEN:franceconnect")).thenReturn("suffixedIdToken");
when(userSession.getNote("FEDERATED_ID_TOKEN")).thenReturn("legacyIdToken");

assertThat(logoutProvider.getIdTokenForLogout(userSession)).isEqualTo("suffixedIdToken");
}

@Test
void should_fall_back_to_the_id_token_note_without_alias() {
when(userSession.getNote("FEDERATED_ID_TOKEN")).thenReturn("legacyIdToken");

assertThat(logoutProvider.getIdTokenForLogout(userSession)).isEqualTo("legacyIdToken");
}
}
}
Loading