![Keycloak イントロスペクトエンドポイントは、token_type_hint が requesting_party_token の場合に非アクティブを返します。](https://rvso.com/image/1711449/Keycloak%20%E3%82%A4%E3%83%B3%E3%83%88%E3%83%AD%E3%82%B9%E3%83%9A%E3%82%AF%E3%83%88%E3%82%A8%E3%83%B3%E3%83%89%E3%83%9D%E3%82%A4%E3%83%B3%E3%83%88%E3%81%AF%E3%80%81token_type_hint%20%E3%81%8C%20requesting_party_token%20%E3%81%AE%E5%A0%B4%E5%90%88%E3%81%AB%E9%9D%9E%E3%82%A2%E3%82%AF%E3%83%86%E3%82%A3%E3%83%96%E3%82%92%E8%BF%94%E3%81%97%E3%81%BE%E3%81%99%E3%80%82.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 は単に非アクティブを返します。