Azure active directory Azure B2C持久Cookie

Azure active directory Azure B2C持久Cookie,azure-active-directory,azure-ad-b2c,Azure Active Directory,Azure Ad B2c,我正在使用配置了一个身份提供商(LinkedIn)的Azure B2C。我有一个Web API(b2c承载身份验证)和一个Web应用程序MVC(b2c开放Id) 我正在尝试创建一个持久登录-这意味着用户可以从给定的设备+浏览器每90天通过LinkedIn登录一次 我得到的最接近的结果是,我在web应用程序中添加了IsPersistent=true代码以启用: 更新:更新了基于Azure B2C GA的代码。为了达到预览版的效果,我仍然使用自定义授权属性,但代码已更新: protected ove

我正在使用配置了一个身份提供商(LinkedIn)的Azure B2C。我有一个Web API(b2c承载身份验证)和一个Web应用程序MVC(b2c开放Id)

我正在尝试创建一个持久登录-这意味着用户可以从给定的设备+浏览器每90天通过LinkedIn登录一次

我得到的最接近的结果是,我在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小时内有效。可能是遵循访问和ID策略?刷新令牌没有限制-我不确定为什么“iPersistent”只有1小时

这就引出了这些问题:

  • 使用Azure B2C(OpenId Connect)是否可以实现持久会话(60-90天)
  • 如果是的话,有没有关于我遗漏了什么的建议?我需要做一些自定义cookie验证吗?带有刷新标记的东西(我在web api中使用它们,但在web应用程序中没有自定义标记)

  • 任何想法或意见都将是伟大的

    在执行以下操作后,我已经能够与B2C实现持久会话:

  • 自定义授权属性

    protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
    {
        filterContext.HttpContext.GetOwinContext()
             .Authentication.Challenge(
                  new AuthenticationProperties() { IsPersistent = true }
              );
        base.HandleUnauthorizedRequest(filterContext);
    }
    
  • 使用Microsoft.Experimental.IdentityModel.Clients.ActiveDirectory而不是BootstrapContext(基本上使用了pre-GA代码示例(查看更改历史)->)。ADAL库处理获取对我的代码透明的适当令牌的过程

  • 实现了自定义令牌缓存(基于此处的EFADAL示例:)

  • 已更改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,
    
        },
    }