Skip to content

Commit d5ae044

Browse files
committed
KNOX-3433: set issued_token_type in KnoxIDF token responses (RFC 8693 §2.2.1)
1 parent 683841b commit d5ae044

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

.github/workflows/tests/test_knoxidf.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def test_client_credentials_flow(self):
9999
tokens = response.json()
100100
self.assertIn("access_token", tokens)
101101
self.assertEqual(tokens["token_type"], "Bearer")
102+
self.assertEqual(tokens["issued_token_type"], "urn:ietf:params:oauth:token-type:jwt")
102103

103104
def test_authorization_code_flow(self):
104105
"""
@@ -136,6 +137,7 @@ def test_authorization_code_flow(self):
136137
self.assertIn("access_token", tokens)
137138
self.assertIn("id_token", tokens)
138139
self.assertIn("refresh_token", tokens)
140+
self.assertEqual(tokens["issued_token_type"], "urn:ietf:params:oauth:token-type:jwt")
139141

140142
refresh_token = tokens["refresh_token"]
141143
print(f"Refresh token: {refresh_token}")
@@ -154,6 +156,7 @@ def test_authorization_code_flow(self):
154156
new_tokens = response.json()
155157
self.assertIn("access_token", new_tokens)
156158
self.assertIn("refresh_token", new_tokens)
159+
self.assertEqual(new_tokens["issued_token_type"], "urn:ietf:params:oauth:token-type:jwt")
157160

158161
# Verify rotation: new refresh token should be different
159162
self.assertNotEqual(refresh_token, new_tokens["refresh_token"])

gateway-service-knoxidf/src/main/java/org/apache/knox/gateway/service/knoxidf/TokenResource.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171
import static org.apache.knox.gateway.util.knoxidf.KnoxIDFConstants.CODE_CHALLENGE_METHOD;
7272
import static org.apache.knox.gateway.util.knoxidf.KnoxIDFConstants.CODE_VERIFIER;
7373
import static org.apache.knox.gateway.util.knoxidf.KnoxIDFConstants.FEDERATED_IDENTITY_ID;
74+
import static org.apache.knox.gateway.util.knoxidf.KnoxIDFConstants.ISSUED_TOKEN_TYPE;
75+
import static org.apache.knox.gateway.util.knoxidf.KnoxIDFConstants.ISSUED_TOKEN_TYPE_JWT_VALUE;
7476
import static org.apache.knox.gateway.util.knoxidf.KnoxIDFConstants.OFFLINE_ACCESS_SCOPE;
7577
import static org.apache.knox.gateway.util.knoxidf.KnoxIDFConstants.PKCE_METHOD_S256;
7678
import static org.apache.knox.gateway.util.knoxidf.KnoxIDFConstants.REDIRECT_URI;
@@ -211,6 +213,11 @@ protected void addArbitraryTokenMetadata(TokenMetadata tokenMetadata) {
211213
protected ResponseMap buildResponseMap(JWT token, long expires) throws TokenServiceException {
212214
final ResponseMap responseMap = super.buildResponseMap(token, expires);
213215

216+
// RFC 8693 §2.2.1 requires the response to state the type of the issued token. Every KnoxIDF
217+
// grant (authorization_code, refresh_token and the client_credentials/other grants routed to
218+
// super.doPost()) funnels through here and mints a JWT, so advertise the JWT URN unconditionally.
219+
responseMap.map.put(ISSUED_TOKEN_TYPE, ISSUED_TOKEN_TYPE_JWT_VALUE);
220+
214221
// id_token + refresh-token rotation apply to the user-centric grants (authorization_code and
215222
// refresh_token). client_credentials and other grants routed to super.doPost() must not get an
216223
// id_token (no end user) and never carry offline_access, so they are excluded here.

gateway-util-common/src/main/java/org/apache/knox/gateway/util/knoxidf/KnoxIDFConstants.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ public interface KnoxIDFConstants {
4444
String STATE = "state";
4545
String CODE = "code";
4646
String REFRESH_TOKEN = "refresh_token";
47+
// RFC 8693 §2.2.1: the token endpoint response must advertise the type of the issued token.
48+
String ISSUED_TOKEN_TYPE = "issued_token_type";
49+
//KnoxIDF always mints a JWT so issued_token_type is the JWT URN rather than the generic access_token URN.
50+
String ISSUED_TOKEN_TYPE_JWT_VALUE = "urn:ietf:params:oauth:token-type:jwt";
4751
String REFRESH_TOKEN_TTL= "refresh.token.ttl";
4852
long REFRESH_TOKEN_TTL_DEFAULT = 86400000L; // 1 day
4953
String CODE_RESPONSE_TYPE = RESPONSE_TYPE + "=" + CODE;

0 commit comments

Comments
 (0)