![當 token_type_hint 正在 requesting_party_token 時,Keycloak 內省端點傳回非活動狀態](https://rvso.com/image/1711449/%E7%95%B6%20token_type_hint%20%E6%AD%A3%E5%9C%A8%20requesting_party_token%20%E6%99%82%EF%BC%8CKeycloak%20%E5%85%A7%E7%9C%81%E7%AB%AF%E9%BB%9E%E5%82%B3%E5%9B%9E%E9%9D%9E%E6%B4%BB%E5%8B%95%E7%8B%80%E6%85%8B.png)
我正在使用 Keycloak 3.4.3-Final。更改 keycloak 版本對我來說不是一個選擇。我創建了一個客戶端和用戶,使用用戶 ID/PW 獲取了一個 JWT,並嘗試內省這個 JWT。當我指定 token_type_hint=requesting_party_token 時,Keycloak 傳回 JWT 處於非活動狀態。如果我省略 token_type_hint,我得到的結果顯示令牌處於活動狀態。
以下是重現問題的方法:
# run keycloak using docker
docker run -d jboss/keycloak:3.4.3.Final
# create a client and user. keycloak config is https://gist.github.com/roengram/9beba13665592322d666a92110ac1ff9
# get a JWT using user ID/PW
curl -s -d \
"client_id=${CLIENT_ID}" \
-d "client_secret=${CLIENT_SECRET}" \
-d "username=${USERID}" -d "password=${USERPW}" \
-d "grant_type=password" \
"${KEYCLOAK_ENDPOINT}/auth/realms/${REALM}/protocol/openid-connect/token"
{"access_token":"eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICI2RUpvU0RnOEtBeHlKUHhjODM3UC1kMFlac1NUS2drU...
# introspect the token according to https://www.keycloak.org/docs/3.4/authorization_services/#obtaining-information-about-an-rpt
curl -X POST \
-u ${CLIENT_ID}:${CLIENT_SECRET} \
-H "Content-Type: application/x-www-form-urlencoded" \
-d 'token_type_hint=requesting_party_token&token=${JWT}' \
"${KEYCLOAK_ENDPOINT}/auth/realms/${REALM}/protocol/openid-connect/token/introspect"
{"active":false}
# if token_type_hint is omitted, active is returned
curl -X POST \
-u ${CLIENT_ID}:${CLIENT_SECRET} \
-H "Content-Type: application/x-www-form-urlencoded" \
-d 'token=${JWT}' \
"${KEYCLOAK_ENDPOINT}/auth/realms/${REALM}/protocol/openid-connect/token/introspect"
{"jti":"89eaa1b0-86bc-4ea2-8bf4-58dca2e3e794","exp":1560252718,"nbf":0,"iat":1560249118,"iss":"http://172.19.0.4:8080/auth/realms/master","aud":"testclient","sub":"843deccc-07f0-45b5-9965-653405a84bfe","typ":"Bearer","azp":"testclient","auth_time":0,"session_state":"eee130fc-00d8-4f0c-912d-d65de81982d0","preferred_username":"roen","acr":"1","allowed-origins":[],"realm_access":{"roles":["uma_authorization"]},"resource_access":{"account":{"roles":["manage-account","manage-account-links","view-profile"]}},"client_id":"testclient","username":"roen","active":true}
也許我使用了錯誤的 token_type_hint?根據規格, token_type_hint 被伺服器選擇性地使用來優化令牌查找,並且可以被忽略。我懷疑我提交給 keycloak 的令牌不是 RPT,因此 keycloak 只是返回非活動狀態。