2016-07-21 131 views
1

我正在使用配置了一個身份提供商(LinkedIn)的Azure B2C。我有一個Web API(b2c承載認證)和一個Web App MVC(b2c Open Id)。Azure B2C持久Cookie

我試圖創建一個持久登錄 - 意味着用戶可以通過LinkedIn從給定設備+瀏覽器每90天進行一次登錄。

我已經得到的最接近的是,當我在Web應用程序中添加IsPersistent = TRUE代碼啓用:

更新:基於Azure的B2C GA更新後的代碼。爲了實現在那裏我是在與預覽,我仍然可以使用自定義的授權屬性,但代碼進行了更新:

protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext) 
    { 
      filterContext.HttpContext.GetOwinContext().Authentication.Challenge(
      new AuthenticationProperties() 
      { 
       IsPersistent = true 
      }); 
     base.HandleUnauthorizedRequest(filterContext); 
    } 

然而,這僅適用於約1小時。也許它遵循Access & ID政策?沒有界限刷新令牌 - 我不知道爲什麼只有1小時的「IsPersistent」。

Token Session Config in Azure

所以導致這些問題:

  1. 是持久會話(60-90天)的東西,我可以用Azure的B2C(ID連接)實現?
  2. 如果是這樣,我缺少什麼指針?我需要做一些自定義Cookie驗證嗎?有刷新令牌的東西(我使用它們作爲web api,但沒有在web應用程序中定製)。

任何想法或輸入將是偉大的!

回答

0

我已經能夠做後實現了B2C的持續性會話如下:

  1. 自定義授權屬性

    protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext) { filterContext.HttpContext.GetOwinContext().Authentication.Challenge( new AuthenticationProperties() { IsPersistent = true }); base.HandleUnauthorizedRequest(filterContext); }

  2. 使用Microsoft.Experimental.IdentityModel.Clients.ActiveDirectory而不是BootstrapContext(基本上與前GA代碼示例(查看更改歷史記錄) - >https://github.com/AzureADQuickStarts/B2C-WebApp-WebAPI-OpenIDConnect-DotNet)。 ADAL庫處理獲取對我的代碼透明的正確標記。

  3. 實現的自定義TokenCache(基於這裏的EFADAL例如:https://github.com/Azure-Samples/active-directory-dotnet-webapp-webapi-multitenant-openidconnect/blob/master/TodoListWebApp/DAL/EFADALTokenCache.cs

  4. 更改Startup.Auth.cs:

    return new OpenIdConnectAuthenticationOptions 
    { 
        MetadataAddress = String.Format(aadInstance, tenant, policy), 
        AuthenticationType = policy, 
        UseTokenLifetime = false, 
        ClientId = clientId, 
        RedirectUri = redirectUri, 
        PostLogoutRedirectUri = redirectUri, 
        Notifications = new OpenIdConnectAuthenticationNotifications 
        { 
    
         AuthenticationFailed = OnAuthenticationFailed, 
         AuthorizationCodeReceived = OnAuthorizationCodeReceived, 
        }, 
        Scope = "openid offline_access", 
        ResponseType = "code id_token", 
    
        TokenValidationParameters = new TokenValidationParameters 
        { 
         NameClaimType = "name", 
         SaveSigninToken = true, 
    
        }, 
    }