Startup.cs 中的 OpenIdConnectAuthenticationOptions 问题(AuthenticationFailed 属性)

use*_*624 5 c# openid authentication owin

我的 Startup.cs 有以下代码

public void ConfigureAuth(IAppBuilder app)
{
    app.UseWindowsAzureActiveDirectoryBearerAuthentication(
        new WindowsAzureActiveDirectoryBearerAuthenticationOptions
        {
            TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters()
            {
                ValidAudience = ConfigurationManager.AppSettings["value1"]
            },
            Tenant = ConfigurationManager.AppSettings["value2"]
        });

    app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

    app.UseCookieAuthentication(new CookieAuthenticationOptions
    {
        CookieManager = new SystemWebCookieManager()
    });

    app.UseKentorOwinCookieSaver(); //Workaround for infinite loop between webapp & login page

    app.UseOpenIdConnectAuthentication(
        new OpenIdConnectAuthenticationOptions
        {
            ClientId = clientId,
            Authority = Authority,
            PostLogoutRedirectUri = redirectUri,
            RedirectUri = redirectUri,

            Notifications = new OpenIdConnectAuthenticationNotifications()
            {
                //
                // If there is a code in the OpenID Connect response, redeem it for an access token and refresh token, and store those away.
                //
                AuthorizationCodeReceived = OnAuthorizationCodeReceived,
                AuthenticationFailed = OnAuthenticationFailed
            }
        });
}

private Task OnAuthenticationFailed(AuthenticationFailedNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions> context)
{
    context.HandleResponse();
    context.Response.Redirect("/Home/Error?message=" + context.Exception.Message);
    return Task.FromResult(0);
}
Run Code Online (Sandbox Code Playgroud)

但是,当我这样做时

AuthenticationFailed = OnAuthenticationFailed

我收到以下错误:错误 CS0123 “OnAuthenticationFailed”没有重载匹配委托 'Func< AuthenticationFailedNotification< OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>, Task>'

我不明白为什么会发生这种情况,因为这里的类型匹配。自从我更新到 Owin 4.0.1 以及所有 Microsoft.IdentityModel 和 System.IdentityModel 到 5.4.0 以来,这一切都开始发生。

我知道 5.X 版中有一些重大更改,但我认为 5.4.0 版已全部解决,这是我留下的唯一问题。

Gij*_*ijs 6

我遇到过同样的问题。更新后Microsoft.IdentityModel的类型OpenIdConnectMessage在不同的命名空间中:

Microsoft.IdentityModel.Protocols.OpenIdConnect
Run Code Online (Sandbox Code Playgroud)