Problem with OpenIdConnectAuthenticationOptions in Startup.cs (AuthenticationFailed property)
Asked Answered
O

3

5

I have the following code for my 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);
}

However, when I do this

AuthenticationFailed = OnAuthenticationFailed

I am getting the following error: Error CS0123 No overload for 'OnAuthenticationFailed' matches delegate 'Func< AuthenticationFailedNotification< OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>, Task>'

I don't see why this is happening since the types match here. It all started happening since I updated to Owin 4.0.1 as well as all the Microsoft.IdentityModel and System.IdentityModel to 5.4.0.

I know there were some breaking changes in the version 5.X but I think there are all resolved on version 5.4.0 and this is the only issue I have left.

Orthopterous answered 5/2, 2019 at 2:11 Comment(0)
S
7

I had the same issue. After updating Microsoft.IdentityModel the type OpenIdConnectMessage is in a different namespace:

Microsoft.IdentityModel.Protocols.OpenIdConnect
Specular answered 11/3, 2019 at 9:14 Comment(0)
S
1

Option 1: use in-line with a lambda anonymous code block

Option 2: For a cleaner separation of concerns:

Use explicit namespace like this

using Microsoft.IdentityModel.Protocols.OpenIdConnect;

Instead of using

Microsoft.IdentityModel.Protocols;

No other change required

Strongarm answered 4/12, 2019 at 5:11 Comment(0)
H
0

This package solved all my problems Microsoft.Owin.Security.OpenIdConnect 4.2.0

Dependencies

  • Microsoft.IdentityModel.Logging (>= 5.3.0)

  • Microsoft.IdentityModel.Protocols (>= 5.3.0)

  • Microsoft.IdentityModel.Protocols.OpenIdConnect (>= 5.3.0)

  • Microsoft.IdentityModel.Tokens (>= 5.3.0)

  • Microsoft.Owin (>= 4.2.0)

  • Microsoft.Owin.Security (>= 4.2.0) Owin (>= 1.0.0)

  • System.IdentityModel.Tokens.Jwt (>= 5.3.0)

Hartford answered 8/12, 2021 at 7:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.