2017-04-13 89 views
0

我們使用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」)。 call fail

看看我們在邊緣得到例如消息: edge iframe error

有沒有辦法來避免這個問題(我們錯過一個參數調用登錄頁面時,或別的東西)?或者它是另一種解決方案嗎?

感謝, 萊奧

回答

相關問題