我安装了Key斗篷18.0.0,并将数据库供应商配置为MySQL。我还创建了一个领域和我的客户。当我请求key斗篷使用grant_type=password、客户端id、用户名和密码进行身份验证时,它会使用访问令牌来响应我,但该访问令牌不包含auth_time声明。知道我该怎么把它包括进来吗?感谢
;auth_time";不包括在Keycloft的访问令牌中。
它包括id令牌。它可以通过添加";openid";调用get token时的作用域。
这是curl 调用的示例
curl --location --request POST 'http://localhost:8180/auth/realms/test/protocol/openid-connect/token'
--header 'Content-Type: application/x-www-form-urlencoded'
--data-urlencode 'grant_type=password'
--data-urlencode 'username=user'
--data-urlencode 'password=1234'
--data-urlencode 'client_id=admin-cli'
--data-urlencode 'scope=openid'
我从jwt.io解码获取";auth_time";宣称
{
"exp": 1660748251,
"iat": 1660730251,
"auth_time": 0,
"jti": "77a2000d-9876-4754-92df-10ca3c93fdbc",
"iss": "http://localhost:8180/auth/realms/test",
"aud": "admin-cli",
"sub": "7a5579a8-485a-435e-83b3-e0e2101ef20c",
"typ": "ID",
"azp": "admin-cli",
"session_state": "255a1543-ccb9-40bf-983f-93057df3f92b",
"at_hash": "anFxw9f0KgIk5dGu5GInBA",
"acr": "1",
"sid": "255a1543-ccb9-40bf-983f-93057df3f92b",
"email_verified": false,
"name": "Tom Cruise",
"preferred_username": "user",
"given_name": "Tom",
"family_name": "Cruise",
"email": "user@test.com"
}
它是零(0(值。我认为这是同一时间;iat";(签发地点(索赔。
我通过更改版本、grant_type和scope对其进行了测试。我发现这取决于这些组合。这是测试结果。默认作用域表示(配置文件电子邮件(,openid表示(openid配置文件邮件(
我不知道原因,只是";auth_time";是可选的,并且会根据条件进行更改。
版本 | 授予类型 | 作用域 | 访问令牌 | ID令牌|
---|---|---|---|---|
19.0.2 | 密码 | 默认值否 | 否 | |
19.0.2 | 密码 | openid否 | auth_time=0 | |
19.0.2 | 代码 | openidauth_time=iat | ||
18.0.2 | 密码 | 默认值否 | 否||
18.0.2 | 密码 | openid | 否auth_time=0 | |
18.0.2 | 代码 | openid