首页 文章

Azure B2C持久性Cookie

提问于
浏览
1

我使用Azure B2C配置了一个身份提供程序(LinkedIn) . 我有一个Web API(b2c bearer auth)和一个Web App MVC(b2c Open Id) .

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

我最接近的是当我在网络应用中添加IsPersistent = true代码时启用:

Update :基于Azure B2C GA更新了代码 . 为了实现我在预览中所处的位置,我仍然使用自定义authorize属性,但代码已更新:

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

但是,这仅有效约1小时 . 也许它遵循Access&ID政策?没有刷新令牌的界限 - 我不知道为什么“IsPersistent”只有1个小时 .

Token Session Config in Azure

这导致了这些问题:

  • 是否可以通过Azure B2C(OpenId Connect)实现持久性会话(60-90天)?

  • 如果是这样,关于我缺少什么的指示?我是否需要进行一些自定义cookie验证?有刷新令牌的东西(我将它们用于web api,但在Web应用程序中没有自定义) .

任何想法或输入都会很棒!

1 回答

  • 0

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

    • 自定义授权属性

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

    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,
    
        },
    }
    

相关问题