首页 > 解决方案 > IdentityServer4 500 内部错误,使用授权端点时缺少 EpochTimeExtensions

问题描述

我正在使用 ASP.NET 为 xamarin 表单应用程序创建一个 wep api 后端,我正在使用 identityserver4 进行身份验证和授权。我想使用授权代码工作流,但是当我尝试启动授权/身份验证请求时遇到问题。

我收到的错误是:System.TypeLoadException:无法从程序集“IdentityModel,Version=4.0.0.0,Culture=neutral,PublicKeyToken=e7877f4675df049f”加载类型“IdentityModel.EpochTimeExtensions”。

我在互联网上的任何地方都没有找到解决此问题的方法。

这是我的 Startup.cs

public class Startup
{
    public IConfiguration Configuration { get; }

    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }


    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        //services.AddAutoMapper();
        services.AddDbContext<SqlDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
        services.AddScoped<IUnitOfWork, UnitOfWork>();
        services.AddIdentityServer()
            .AddInMemoryIdentityResources(Config.GetResources())
            .AddInMemoryApiResources(Config.GetApis())
            .AddInMemoryClients(Config.GetClients())
            .AddDeveloperSigningCredential();
        services.AddControllers()
            .AddNewtonsoftJson();
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
            app.UseHsts();
        }

        app.UseHttpsRedirection();

        app.UseRouting();

        app.UseIdentityServer();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
            endpoints.MapGet("/", async context =>
            {
                await context.Response.WriteAsync("Hello World !");
            });
        });
    }
}

这是我的 config.cs:

public class Config
{
    public static IEnumerable<ApiResource> GetApis()
    {
        return new List<ApiResource>
        {
            new ApiResource("Test", "TestService")
        };
    }

    public static IEnumerable<IdentityResource> GetResources()
    {
        return new List<IdentityResource>
        {
            new IdentityResources.OpenId()
        };
    }

    public static IEnumerable<Client> GetClients()
    {
        return new List<Client>
        {
            new Client
            {
                ClientId = "client",
                AllowedGrantTypes = GrantTypes.Code,
                RequireClientSecret = false,
                RequireConsent = false,
                AllowedScopes = new List<string>{ "Test" , "openid"},
                AllowOfflineAccess = true,
                RedirectUris = new List<String> {
                    "https://localhost:44392/account/test/"
                }
            }
        };
    }
 }

这是我的请求网址:

https://localhost:44392/connect/authorize?client_id=client&response_type=code&redirect_uri=https://localhost:44392/account/test/&scope=Test openid&nonce=5&state=5

我希望这里有人可以帮助我。提前致谢

标签: c#asp.netidentityserver4

解决方案


推荐阅读