DominusFlevit
DominusFlevit

Reputation: 11

IdentityServer4 (3.0.0) exception adding OpenIdConnect

When I call AddOpenIdConnect(), I get an exception:

An unhandled exception occurred while processing the request. TypeLoadException: Could not load type 'Microsoft.AspNetCore.Authentication.RequestPathBaseCookieBuilder' from assembly 'Microsoft.AspNetCore.Authentication, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.

Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectOptions..ctor()

Example Code:

        public void ConfigureServices(IServiceCollection services)
        {           
            services.AddMvc();

            var builder = services.AddIdentityServer(options =>
            {
                options.Events.RaiseErrorEvents = true;
                options.Events.RaiseInformationEvents = true;
                options.Events.RaiseFailureEvents = true;
                options.Events.RaiseSuccessEvents = true;
            })
            .AddInMemoryIdentityResources(Config.GetIdentityResources())
            .AddInMemoryApiResources(Config.GetApis())
            .AddInMemoryClients(Config.GetClients());

            services.AddAuthentication()
                .AddOpenIdConnect("aad", "Azure AD", options =>
                {
                    options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
                    options.SignOutScheme = IdentityServerConstants.SignoutScheme;

                    options.Authority = "https://login.windows.net/...";
                    options.ClientId = "client_id";
                    options.ResponseType = "id_token";
                    options.CallbackPath = new PathString("/signin-aad");
                    options.SignedOutCallbackPath = new PathString("/signout-callback-aad");
                    options.RemoteSignOutPath = new PathString("/signout-aad");
                    options.TokenValidationParameters = new TokenValidationParameters
                    {
                        NameClaimType = "name",
                        RoleClaimType = "role"
                    };
                });
        }

Upvotes: 1

Views: 938

Answers (2)

MaPi
MaPi

Reputation: 1601

You need to add an updated nuget reference to Microsoft.AspNetCore.Authentication.OpenIdConnect (now it's at 3.3.1).

This DLL only targets netcore, so you will have to change the TargetFramework from netstandard to netcoreapp.

Which sucks, but I do not believe there is any other option.

Upvotes: 2

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 116869

You forgot to add the cookie Adding User Authentication with OpenID Connect

services.AddAuthentication(options =>
    {
        options.DefaultScheme = "Cookies";
        options.DefaultChallengeScheme = "oidc";
    })
    .AddCookie("Cookies")
    .AddOpenIdConnect("oidc", options =>
    {
        options.Authority = "http://localhost:5000";
        options.RequireHttpsMetadata = false;

        options.ClientId = "mvc";
        options.SaveTokens = true;
    });

Upvotes: 0

Related Questions