小编ama*_*591的帖子

同时使用app.UseOpenIdConnectAuthentication时不使用CookieAuthenticationOptions.LoginPath值

我正在使用OWIN中间件进行Cookie身份验证和openIdConnect。在向cookie身份验证选项的启动身份验证代码中添加openIdConnect身份验证之前,LoginPath被用作重定向未经身份验证的用户的目标。这确实很好,并且是我想保留的功能。

但是,当我将app.UseOpenIdConnectAuthentication添加到我的项目时,它开始自动将未经身份验证的用户重定向到我的OpenIdConnect授权(https://login.windows.net/)。

有没有一种方法可以禁用OpenIdConnectAuthentication设置未经身份验证的用户的重定向路径,并依靠LoginPath设置Cookie身份验证?我目前的解决方法是在我的authorize属性中手动设置重定向路径,但是我想让OWIN中间件在可能的情况下进行处理。

谢谢。

码:

public void ConfigureAuth(IAppBuilder app)
    {
        // Enable the application to use a cookie to store information for the signed in user
        // and to use a cookie to temporarily store information about a user logging in with a third party login provider
        var cookieOptions = new CookieAuthenticationOptions();
        cookieOptions.AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie;
        cookieOptions.LoginPath = new PathString("/Account/Login");

        app.SetDefaultSignInAsAuthenticationType(cookieOptions.AuthenticationType);

        app.UseCookieAuthentication(cookieOptions);

        app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
        {
            AuthenticationType = FranchiseAuthType,
            ClientId = franchiseClientId,
            Authority = FranchiseAuthority,
            PostLogoutRedirectUri = postLogoutRedirectUri,
        });
}
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc owin azure-active-directory openid-connect

2
推荐指数
1
解决办法
3158
查看次数