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

问题描述 投票:1回答:1

我的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);
}

但是,当我这样做

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都已解决,这是我留下的唯一问题。

c# authentication owin openid
1个回答
1
投票

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

干杯,Gijs Stuga车手

© www.soinside.com 2019 - 2024. All rights reserved.