Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migration To NET6

I tried to migrate my ASP CORE project to NET6 My project uses next packages

IdentityServer4.AccessTokenValidation - 3.0.1

IdentityModel.AspNetCore.OAuth2Introspection - 4.0.1

IdentityModel - 5.2.0

The build of project is success. But when I run application I get error

MissingMethodException: Method not found: 'IdentityModel.Client.DiscoveryEndpoint IdentityModel.Client.DiscoveryEndpoint.ParseUrl(System.String)'.
IdentityServer4.AccessTokenValidation.IdentityServerAuthenticationOptions.ConfigureJwtBearer(JwtBearerOptions jwtOptions)
IdentityServer4.AccessTokenValidation.ConfigureInternalOptions.Configure(string name, JwtBearerOptions options)
Microsoft.Extensions.Options.OptionsFactory<TOptions>.Create(string name)
Microsoft.Extensions.Options.OptionsMonitor<TOptions>+<>c__DisplayClass10_0.<Get>b__0()

Anybody had this issue ?

like image 569
Roman Avatar asked Dec 21 '25 20:12

Roman


1 Answers

Roman's answer is correct, we can fix it by doing the IdentityModel downgrade, but another way to fix that issue is by replacing the IdentityServer4.AccessTokenValidation by Microsoft.AspNetCore.Authentication.JwtBearer, and we can change a little bit the token validation, using IdentityServer4.AccessTokenValidation we were doing the validation like this:

services
    .AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme)
    .AddIdentityServerAuthentication(
        options =>
        {
            options.Authority = configuration["Authentication:Authority"];
            options.ApiName = configuration["Authentication:ApiName"];
        });

Now we can do the token validation using the Microsoft.AspNetCore.Authentication.JwtBearer like that:

services
    .AddAuthentication(options =>
    {
        options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
        options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
    })
    .AddJwtBearer(options =>
    {
        options.Authority = configuration["Authentication:Authority"];
        options.RequireHttpsMetadata = false;
        options.TokenValidationParameters.ValidAudiences = new List<string>() { configuration["Authentication:ApiName"] };
    });
like image 72
Matheus Xavier Avatar answered Dec 24 '25 10:12

Matheus Xavier



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!