有谁能给我提供解决这个错误的方法吗?我不明白在配置IdentityServer4时,我哪里错了?

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

图片在此为邮递员请求这是我最后不能理解的一个问题,就是它总能得到一个 {"错误"。"invalid_request"}.

我使用ImplicitFlow和OAuth 2.0向Postman发出请求,但我总是得到同样的错误。

我在下面附上我为IdentityServer4所做的设置。希望对大家有用,能给我一个解决方案。

public static class Config
{
    public static IEnumerable<ApiResource> ApiResources()
    {
        return new[] {
            new ApiResource("SkyEye.API", "SkyEye.API")
        };
    }

    public static IEnumerable<Client> GetClients()
    {
        return new List<Client>
        {
            new Client
            {
                ClientId="ReactClient",
                ClientName="SkyEye.SPA",
                AllowedGrantTypes = GrantTypes.Implicit,
                AllowAccessTokensViaBrowser = true,
                RedirectUris = new List<string>
                {
                    "https://localhost:5002",
                },
                PostLogoutRedirectUris = new []{
                    "https://localhost:5002"
                },
                AllowedScopes= {
                //    IdentityServerConstants.StandardScopes.Profile,
                //    IdentityServerConstants.StandardScopes.OpenId,
                   "SkyEye.API"
                }
            }
        };
    }

    public static IEnumerable<TestUser> Users()
    {
        return new[]
        {
            new TestUser
            {  SubjectId = "1",
                Username = "lascodaniil",
                Password="password"
            }
        };
    }



public class Startup
{

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

    public IConfiguration Configuration { get; }
    public void ConfigureServices(IServiceCollection services)
    {

        services.AddControllers();

        services.AddIdentityServer()
            .AddDeveloperSigningCredential()
            .AddTestUsers(Config.Users().ToList())
            .AddInMemoryClients(Config.GetClients())
            .AddInMemoryApiResources(Config.ApiResources());


    }
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {

        app.UseDeveloperExceptionPage();
        app.UseIdentityServer();
        app.UseRouting();
        app.UseEndpoints(endpoints =>
        {
            endpoints.MapDefaultControllerRoute();
        });
    }
asp.net-core asp.net-identity identityserver4
1个回答
0
投票

我想你的重定向URL是无效的。postman中的URL与IDs配置中提供的URL不同。URL应该是完全匹配的

试着改变这个

RedirectUris = new List<string>
{
    "https://localhost:5002",
},

对此

RedirectUris = new List<string>
{
    "https://localhost:5002/connect/token",
},

希望能帮到你

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