Azure B2C - 刷新令牌中令人困惑的过期字段

问题描述 投票:0回答:1

我在 .NET Core Web api 项目中使用 Azure B2C 进行身份验证。我正在尝试使用文档中概述的步骤更新刷新令牌 - https://learn.microsoft.com/en-us/azure/active-directory-b2c/authorization-code-flow#4-refresh-the-token .

我发送的请求参数(使用RestSharp)如下:

var request = new RestRequest();
request.Method = Method.Post;
request.AddHeader("content-type", "application/x-www-form-urlencoded");
request.AddParameter("grant_type", "refresh_token", ParameterType.GetOrPost);
request.AddParameter("client_id", CLIENT_ID_HERE, ParameterType.GetOrPost);
request.AddParameter("scope", "CLIENT_ID_HERE offline_access", ParameterType.GetOrPost);
request.AddParameter("refresh_token", OLD_REFRESH_TOKEN, ParameterType.GetOrPost);

我收到成功回复,如下图:

{
    "access_token":"eyJhbGciOiJSUzI1NiIsImtp......",
    "id_token":"eyJhbGciOiJS......",
    "token_type":"Bearer",
    "not_before":1720104657,
    "expires_in":3600,
    "expires_on":1720108257,
    "resource":"guid-here",
    "id_token_expires_in":3600,
    "profile_info":"eyJ2ZXIiO.........",
    "scope":"B2C_Client_Id offline_access openid",
    "refresh_token":"eyJraWQiOiJjcGltY29yZ...........",
    "refresh_token_expires_in":76887
}

文档中未提及很少的响应参数 -

refresh_token_expires_in
expires_on
等。

现在,对于 json 响应,我有一些困惑/疑问:

  1. 默认刷新令牌有效期为 14 天,可以延长至 90 天。但。
    refresh_token_expires_in
    中的值以秒为单位,而不是unix时间戳。这是正确的吗?
  2. expires_on
    中的值是unix时间戳,转换为54天。这里可能会过期什么?

我在这里可以得出的结论是,过期令牌的 14 天或 90 天过期不会出现在

refresh_token_expires_in
的 json 响应中;相反,它仅驻留在 B2C 设置中。

有什么想法吗?

azure-ad-b2c aad-b2c
1个回答
0
投票

如本MS 文档中所述,

使用 PKCE 授权码流程的单页应用程序 刷新令牌生命周期始终为 24 小时

最初,我通过 Postman 使用授权代码流和 PKCE 生成令牌,并获得

refresh_token_expires_in
86400 秒(24 小时)。

enter image description here

当我在 30 分钟后使用上面的刷新令牌获取新的访问令牌时,我得到的令牌

refresh_token_expires_in
值减少了 30 分钟(1800 秒):

POST https://{tenant}.b2clogin.com/{tenant}.onmicrosoft.com/{policy}/oauth2/v2.0/token HTTP/1.1
Content-Type: application/x-www-form-urlencoded

grant_type=refresh_token
&client_id=appId
&scope=appId offline_access openid
&refresh_token=refresh_token_value
&redirect_uri=https://jwt.ms

enter image description here

expires_on
中的值是unix时间戳,转换为54 天。这里可能会过期什么?

expires_on
中的值是指访问令牌的到期日期时间。您可以通过解码访问令牌 jwt.ms 网站,检查 exp 声明值是否相同来
确认

enter image description here

您还可以单击

Claims
选项卡,显示访问令牌的确切到期日期时间,如下所示:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.