始终返回IdentityServer"invalid_client"错误

aro*_*gab 14 c# oauth-2.0 postman openid-connect identityserver3

我正在尝试使用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);
}
Run Code Online (Sandbox Code Playgroud)

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"
                }
            }
        };
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我一直得到的结果.

邮差错误

我正在使用邮递员来试用Auth服务器,但我总是得到那个错误.我已经阅读了另一种解决方案,但没有任何看法可行,我不知道还有什么可以尝试.

干杯.

HIT*_*IYA 10

只需在您的正文中添加client_secret:secret 即可。它会起作用!

在此处输入图片说明

  • 嗨@hitesh,它对我不起作用。我也面临同样的问题 (2认同)

yes*_*man 5

迟到的答案,但对我来说,当尝试使用用户名和密码登录时,这是在 IdentityServer 4 教程之后发生的。我使用了第一个教程中的代码(使用客户端凭据),并修改了客户端以使用密码。之后,我不断收到此错误。

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


Art*_*tem 3

您的请求应该如下:

  1. clientId带/的授权标头clientSecret。carbon/secret在你的情况下。1
  2. 在身体里。username/password应该是alice/password在你的情况下。如果您不需要刷新令牌,您可以offline_access从请求中排除范围。2