我们使用Azure的AD B2C我们在ASP.NET MVC应用程序用户OWIN(Microsoft.Owin.Security)进行身份验证。Azure的AD B2C的OAuth2如何刷新访问令牌默默
我们正试图找到一种静默刷新访问令牌(access_token)的方法,以避免我们正在做的多个AJAX调用失败。它们中的大多数是由我们使用的组件(DevExpress)通过回调自动触发的,所以我们对它们几乎没有控制权。 一个解决方案,我们发现的是维托里奥Bertocci在他的博客中所描述的:http://www.cloudidentity.com/blog/2016/07/25/controlling-a-web-apps-session-duration-2/
AccountController.cs
public void ForcedSignIn()
{
HttpContext.GetOwinContext().Authentication.Challenge(new AuthenticationProperties {RedirectUri = "/Account/AfterForcedSignIn"}, "OUR_B2C_SIGNIN_POLICY_ID");
}
_Layout.cshtml
<script>
setInterval(function() {
@if (Request.IsAuthenticated)
{
<text>
var renewUrl = "/Account/ForcedSignIn";
var element = document.getElementById("renewSession");
console.log("sending request to: " + renewUrl);
element.src = renewUrl;
</text>
}
},
1000 * 20
);
</script>
<body>
<iframe id="renewSession" style="height: 600px; width: 600px;"></iframe>
AfterForcedSignIn.cshtml
@{
Layout = null;
}
但是,https://login.microsoftonline.com的调用失败,因为它不能嵌入到iFrame中(即使我们将“prompt”参数指定为“none”)。
有没有办法来避免这个问题(我们错过一个参数调用登录页面时,或别的东西)?或者它是另一种解决方案吗?
感谢, 莱奥