IdentityServer“invalid_client”错误总是返回

问题描述 投票:13回答:3

我试图用IdentityServer3,但不知道为什么我得到“invalid_client”错误总是,总是不管我做什么。

这是我使用的代码:

//Startup.cs (Auth c# project)
public void Configuration(IAppBuilder app) {
    var inMemoryManager = new InMemoryManager();
    var factory = new IdentityServerServiceFactory()
        .UseInMemoryClients(inMemoryManager.GetClients())
        .UseInMemoryScopes(inMemoryManager.GetScopes())
        .UseInMemoryUsers(inMemoryManager.GetUsers());

    var options = new IdentityServerOptions {
        Factory = factory,
        RequireSsl = false
    };

    app.UseIdentityServer(options);
}

InMemoryManager帮手。

//InMemoryManager.cs
public class InMemoryManager {
    public List<InMemoryUser> GetUsers() {
        return new List<InMemoryUser> {
            new InMemoryUser {
                Username = "alice",
                Password = "password",
                Subject = "2",
                Claims = new [] {
                    new Claim("User name", "Alice")
                }
            }
        };
    }

    public IEnumerable<Scope> GetScopes() {
        return new[] {
            new Scope {
                Name = "api1",
                DisplayName = "API 1"
            }
        };
    }

    public IEnumerable<Client> GetClients() {
        return new[] {
            new Client {
                ClientName = "Silicon on behalf of Carbon Client",
                ClientId = "carbon",
                Enabled = true,
                //AccessTokenType = AccessTokenType.Reference,

                Flow = Flows.ResourceOwner,

                ClientSecrets = new List<Secret> {
                    new Secret("secret".Sha256())
                },

                AllowedScopes = new List<string> {
                    "api1"
                }
            }
        };
    }
}

这是结果,我总是得到。

Postman error

我使用的邮递员尝试验证服务器,但我总是得到这个错误。我读过另一个解决方案,但没有SeeME所到的作品,我不知道还有什么尝试。

干杯。

c# oauth-2.0 postman identityserver3 openid-connect
3个回答
2
投票

在你的身体的秘密:只要添加client_secret。它的工作!

enter image description here


1
投票

您的要求应该如下:

  1. 授权报头与clientId / clientSecretcarbon / secret你的情况。
  2. 在身体。 username / password 768,16你的情况alice / password。如果你不需要刷新令牌,你可能会排除请求offline_access范围。

0
投票

迟到的回答,但对我来说这件事发生试图用一个用户名和密码登录时要遵循IdentityServer 4教程。我使用的代码从所述第一教程(使用客户端凭证),和修饰的客户端使用的密码。后来,我不断收到此错误。

为了解决这个问题,在IdentityServer项目,config.cs,在GetClients方法,设置AllowedGrantTypesGrantTypes.ResourceOwnerPassword,并ClientIdclient改变ro.client(或任何客户端名称是您在客户端项目的Program.cs中使用)。

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