简体   繁体   English

ADB2C refresh_token 总是在一天后过期

[英]ADB2C refresh_token always expires in one day

I've been struggling with adb2c for a while now.我一直在为 adb2c 苦苦挣扎。 In particular the refresh flow.特别是刷新流程。 I'm using the latest version of msal-browser and everthing works fine, refreshing the token works well.我正在使用最新版本的msal-browser ,一切正常,刷新令牌效果很好。 The only problem is that the token endpoint returns a refresh_token that will always expire in one day.唯一的问题是令牌端点返回一个总是在一天后过期的refresh_token In this case, a user can only be logged in for a day, after that, the user will always have to re-authorize.在这种情况下,用户只能登录一天,之后,用户将始终需要重新授权。 Here is an example of the endpoint and what it returns directly after logging in. (note that I have set the access_token expire time on 5 mins for testing purposes)这是端点的示例以及它在登录后直接返回的内容。(请注意,出于测试目的,我已将access_token过期时间设置为 5 分钟)

Endpoint:端点:

https://{b2c_domain.onmicrosoft.com/{b2c_policy}/oauth2/v2.0/token

Response:回复:

{
    "access_token": "{access_token_hidden}",
    "id_token": "{id_token_hidden}",
    "token_type": "Bearer",
    "not_before": 1610023338,
    "expires_in": 300,
    "expires_on": 1610023638,
    "resource": "{resource_hidden}",
    "client_info": "{client_info}",
    "scope": "https://{adb2c_domain_hidden}.onmicrosoft.com/api/user_impersonation",
    "refresh_token": "{refresh_token_hidden}",
    "refresh_token_expires_in": 86400
}

When, at some point, the application will try to refresh a token, it will call the token endpoint again.当应用程序在某个时候尝试刷新令牌时,它将再次调用令牌端点。 This is what a second response looks like:这是第二个响应的样子:

{
    "access_token": "{access_token_hidden}",
    "id_token": "{id_token_hidden}",
    "token_type": "Bearer",
    "not_before": 1610023891,
    "expires_in": 300,
    "expires_on": 1610024191,
    "resource": "{resource_hidden}",
    "client_info": "{client_info}",
    "scope": "https://{adb2c_domain_hidden}.onmicrosoft.com/api/user_impersonation",
    "refresh_token": "{refresh_token_hidden}",
    "refresh_token_expires_in": 85846
}

The refresh_token_expires_in is not rolling. refresh_token_expires_in没有滚动。 But that is understandable, the user should not always stay logged in. But, in my adb2c policy the following settings are active:但这是可以理解的,用户不应该始终保持登录状态。但是,在我的 adb2c 策略中,以下设置处于活动状态:

在此处输入图像描述

I would assume, as I have configured in the settings, the refresh token should at least be active for 14 days.我会假设,正如我在设置中配置的那样,刷新令牌应该至少激活 14 天。 If not, even up to 90 days?如果没有,甚至长达 90 天? I can play with the settings, but it will always give me a refresh_token that lasts for 1 day.我可以使用这些设置,但它总是会给我一个持续 1 天的 refresh_token。 Does anyone has any experience with this or has a possible solution?有没有人有这方面的经验或有可能的解决方案? Thanks!谢谢!

Yes, as you think, the lifetime of the refresh token can be up to 90 days.是的,如您所想, 刷新令牌的生命周期最长可达 90 天。 If you need to configure the lifetime of the refresh token, you should use powershell to create a token lifetime policy, and then assign the policy to your service principal to set the token lifetime.如果您需要配置刷新令牌的生命周期,您应该使用 powershell 创建令牌生命周期策略,然后将该策略分配给您的服务主体以设置令牌生命周期。 See: here .见: 这里


Update:更新:

I just used the Azure AD B2C portal to set the lifetime of the refresh token to 14 days, and then tested it with the ROPC user flow , and the result was that it did take effect.我刚刚用Azure AD B2C门户将刷新令牌的生命周期设置为14天,然后用ROPC用户流进行测试,结果确实生效了。 The refresh token I got was 14 days.我得到的刷新令牌是 14 天。

So, please make sure that the user flow that you set the lifetime of for the refresh token is the user flow you are using, which is very important!所以,请确保您为刷新令牌设置生命周期的用户流是您正在使用的用户流,这一点非常重要!

By the way, your endpoint is wrong, it should be:顺便说一句,您的端点是错误的,应该是:

https://<tenant-name>.b2clogin.com/<tenant-name>.onmicrosoft.com/{b2c_policy}/oauth2/v2.0/token

在此处输入图像描述

2. 2.

在此处输入图像描述

3. 3.

在此处输入图像描述

If you are using the Msal-Browser which implements the code grant with PKCE in SPA application.如果您使用的是在 SPA 应用程序中使用 PKCE 实现代码授权的 Msal-Browser。 For this case, you will get the refresh token which will have a expiry of 24 hours and that is not rolling.对于这种情况,您将获得 24 小时到期且不会滚动的刷新令牌。 After 24 hours you need to go to /authorization endpoint of azure ad to get the new access and refresh token. 24 小时后,您需要 go 到 azure 广告的 /authorization 端点以获取新的访问和刷新令牌。 This can also be also non-interactive flow if the browser has the valid login session.如果浏览器具有有效的登录 session,这也可以是非交互式流程。

In the Msal-browser library, If you have configured the session more than 24 hours then you can perform the Silent login with ssoSilent(), it require you to send the login_hint.在 Msal 浏览器库中,如果您已配置 session 超过 24 小时,则可以使用 ssoSilent() 执行静默登录,它需要您发送 login_hint。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM