8000 Add feature flag for setting header type "at+jwt" in access tokens by laurids · Pull Request #37439 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Closed
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
2 changes: 2 additions & 0 deletions common/src/main/java/org/keycloak/common/Profile.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ public enum Feature {
IPA_TUURA_FEDERATION("IPA-Tuura user federation provider", Type.EXPERIMENTAL),

ROLLING_UPDATES("Rolling Updates", Type.PREVIEW),

JWT_ACCESS_TOKEN_TYPE_RFC9068("Access tokens get header type 'at+jwt'", Type.EXPERIMENTAL),
;

private final Type type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.jboss.logging.Logger;
import org.keycloak.Token;
import org.keycloak.TokenCategory;
import org.keycloak.common.Profile;
import org.keycloak.common.util.Time;
import org.keycloak.crypto.Algorithm;
import org.keycloak.crypto.CekManagementProvider;
Expand Down Expand Up @@ -238,6 +239,10 @@ public String encodeAndEncrypt(Token token) {

private String type(TokenCategory category) {
switch (category) {
case ACCESS:
return Profile.isFeatureEnabled(Profile.Feature.JWT_ACCESS_TOKEN_TYPE_RFC9068)
? TokenUtil.TOKEN_TYPE_JWT_ACCESS_TOKEN
: "JWT";
case LOGOUT:
return TokenUtil.TOKEN_TYPE_JWT_LOGOUT_TOKEN;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import org.keycloak.testsuite.AssertEvents;
import org.keycloak.testsuite.ProfileAssume;
import org.keycloak.testsuite.admin.ApiUtil;
import org.keycloak.testsuite.arquillian.annotation.EnableFeature;
import org.keycloak.testsuite.util.AdminClientUtil;
import org.keycloak.testsuite.util.ClientBuilder;
import org.keycloak.testsuite.util.ClientManager;
Expand Down Expand Up @@ -1485,4 +1486,27 @@ public void tokenRequestParamsMoreThanOnce() throws Exception {
}
}

@Test
@EnableFeature(value = Profile.Feature.JWT_ACCESS_TOKEN_TYPE_RFC9068, skipRestart = true)
public void accessTokenRequestWithRfc9068HeaderType() throws Exception {
oauth.doLogin("test-user@localhost", "password");

String code = oauth.getCurrentQuery().get(OAuth2Constants.CODE);
AccessTokenResponse response = oauth.doAccessTokenRequest(code, "password");

assertEquals(200, response.getStatusCode());

assertEquals("Bearer", response.getTokenType());

JWSHeader header = new JWSInput(response.getAccessToken()).getHeader();
assertEquals("at+jwt", header.getType());

header = new JWSInput(response.getIdToken()).getHeader();
assertEquals("JWT", header.getType());

header = new JWSInput(response.getRefreshToken()).getHeader();
assertEquals("JWT", header.getType());

oauth.verifyToken(response.getAccessToken());
}
}
0