8.5.2. 获取有关 RPT 的信息
令牌内省基本上是一个 OAuth2 令牌内省与端点,您可以从中获取有关 RPT 的信息。
http://${host}:${port}/realms/${realm-name}/protocol/openid-connect/token/introspect
要使用此端点内省 RPT,您可以向服务器发送请求,如下所示:
curl -X POST \
-H "Authorization: Basic aGVsbG8td29ybGQtYXV0aHotc2VydmljZTpzZWNyZXQ=" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d 'token_type_hint=requesting_party_token&token=${RPT}' \
"http://localhost:8080/realms/hello-world-authz/protocol/openid-connect/token/introspect"
注意
上面的请求使用 HTTP BASIC,并传递客户端的凭据(客户端 ID 和机密),以验证尝试内省令牌的客户端,但您可以使用红帽构建的 Keycloak 支持的任何其他客户端验证方法。
内省端点需要两个参数:
token_type_hint
使用 request_party_token 作为此参数的值,这表示您要内省 RPT。
token
在授权过程中,使用令牌字符串作为此参数的值,由服务器在授权过程中返回。
因此,服务器响应:
{
"permissions": [
{
"resource_id": "90ccc6fc-b296-4cd1-881e-089e1ee15957",
"resource_name": "Hello World Resource"
}
],
"exp": 1465314139,
"nbf": 0,
"iat": 1465313839,
"aud": "hello-world-authz-service",
"active": true
}
如果 RPT 未激活,则返回这个响应:
{
"active": false
}