8000 Set logout token type to logout+jwt by justin-tay · Pull Request #29260 · keycloak/keycloak · GitHub
[go: up one dir, main page]

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
3 changes: 3 additions & 0 deletions core/src/main/java/org/keycloak/util/TokenUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public class TokenUtil {
public static final String TOKEN_TYPE_JWT_ACCESS_TOKEN = "at+jwt";
public static final String TOKEN_TYPE_JWT_ACCESS_TOKEN_PREFIXED = "application/" + TOKEN_TYPE_JWT_ACCESS_TOKEN;

// https://openid.net/specs/openid-connect-backchannel-1_0.html#LogoutToken
public static final String TOKEN_TYPE_JWT_LOGOUT_TOKEN = "logout+jwt";

public static final String TOKEN_TYPE_KEYCLOAK_ID = "Serialized-ID";

public static final String TOKEN_TYPE_ID = "ID";
Expand Down
8000
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ public String encode(Token token) {
SignatureProvider signatureProvider = session.getProvider(SignatureProvider.class, signatureAlgorithm);
SignatureSignerContext signer = signatureProvider.signer();

String encodedToken = new JWSBuilder().type("JWT").jsonContent(token).sign(signer);
String type = type(token.getCategory());
String encodedToken = new JWSBuilder().type(type).jsonContent(token).sign(signer);
return encodedToken;
}

Expand Down Expand Up @@ -235,6 +236,15 @@ public String encodeAndEncrypt(Token token) {
return encodedToken;
}

private String type(TokenCategory category) {
switch (category) {
case LOGOUT:
return TokenUtil.TOKEN_TYPE_JWT_LOGOUT_TOKEN;
default:
return "JWT";
}
}

private boolean isTokenEncryptRequired(TokenCategory category) {
if (cekManagementAlgorithm(category) == null) return false;
if (encryptAlgorithm(category) == null) return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,12 @@ public void backChannelPreferenceOverKLogout() throws Exception {
MatcherAssert.assertThat(response.getFirstHeader(HttpHeaders.LOCATION).getValue(), is(oauth.APP_AUTH_ROOT));
}

validateLogoutToken(testingClient.testApp().getBackChannelLogoutToken());
String rawLogoutToken = testingClient.testApp().getBackChannelRawLogoutToken();
JWSInput jwsInput = new JWSInput(rawLogoutToken);
LogoutToken logoutToken = jwsInput.readJsonContent(LogoutToken.class);
validateLogoutToken(logoutToken);
JWSHeader logoutTokenHeader = jwsInput.getHeader();
assertEquals("logout+jwt", logoutTokenHeader.getType());
} finally {
rep.getAttributes().put(OIDCConfigAttributes.BACKCHANNEL_LOGOUT_URL, "");
clientResource.update(rep);
Expand Down
0