【问题标题】:IdentityServer "invalid_client" error always returnedIdentityServer“invalid_client”错误总是返回
【发布时间】:2017-04-24 07:44:52
【问题描述】:

我正在尝试使用 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"
                }
            }
        };
    }
}

这是我一直得到的结果。

我正在使用邮递员来尝试身份验证服务器,但我总是收到该错误。我已经阅读了其他解决方案,但似乎没有一个可行,我不知道还有什么可以尝试的。

干杯。

【问题讨论】:

  • 前一周我遇到了这个错误的问题,但我们使用的是授权码授权,它与重定向 URI 有关 - 你能在日志中看到任何内容吗?
  • 您是否启用并检查了日志?他们提供了很多信息
  • 你使用的是什么流量。它是资源所有者吗?
  • 与往常一样,启用日志记录以确定问题所在。
  • @arosgab 您能否发布一个回答您自己的问题的答案,显示 IdentityServer 配置和邮递员的请求详细信息?就像您提出答案一样,但现在使用正确的配置,以便在没有 invalid_client 错误的情况下发出请求。

标签: c# oauth-2.0 postman identityserver3 openid-connect


【解决方案1】:

只需在您的 Body 中添加 client_secret: secret。它会起作用的!

【讨论】:

  • 嗨@hitesh,它不适合我。我也面临同样的问题
【解决方案2】:

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

要修复它,在 IdentityServer 项目 config.cs 中,在 GetClients 方法中,将 AllowedGrantTypes 设置为 GrantTypes.ResourceOwnerPassword,并将 ClientIdclient 更改为 ro.client(或任何客户端name 是您在 Client 项目的 program.cs 中使用的名称)。

【讨论】:

  • 你拯救了我的一天
【解决方案3】:

您的请求应该如下:

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

【讨论】:

    猜你喜欢
    • 2019-05-22
    • 1970-01-01
    • 2019-12-18
    • 2012-02-26
    • 2014-05-29
    • 1970-01-01
    • 1970-01-01
    • 2020-05-15
    • 1970-01-01
    相关资源
    最近更新 更多