【发布时间】:2015-04-08 10:23:48
【问题描述】:
我在集成外部提供商时遇到问题,即 Google 与 Thinktecture 身份服务器 v3。我收到以下错误:“客户端应用程序未知或未授权。” 有没有人知道这个错误。
【问题讨论】:
-
我也有同样的问题
我在集成外部提供商时遇到问题,即 Google 与 Thinktecture 身份服务器 v3。我收到以下错误:“客户端应用程序未知或未授权。” 有没有人知道这个错误。
【问题讨论】:
@Whoever,看起来您在客户端和服务器中的 RedirectUri 值不匹配。
客户端启动中的 RedirectUri 属性定义了在身份服务器进行身份验证后将调用的 URI。服务器配置中的 RedirectUris 定义了可以请求身份验证的允许 URI 列表。因此,客户端启动 RedirectUri 必须包含在服务器的 RedirectUris 列表中。
看起来您客户端的 RedirectUri 当前指向服务器的 URI。您的客户端是否在端口 46289 上运行?如果是这样,请尝试将客户端启动中的 RedirectUri 属性的值更改为https://localhost:46289。您可能还想尝试修改服务器的 redirectUris 值以使用 https 而不是 http,假设您的客户端确实可以通过 https 访问。
服务器客户端存储:
public static IEnumerable<Client> Get()
{
return new[] {
new Client {
Enabled = true,
ClientName = "MVC Client",
ClientId = "mvc",
Flow = Flows.Implicit,
RedirectUris = new List<string>{
"https://localhost:46289/" // client home url
客户端启动:
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
app.UseCookieAuthentication(new CookieAuthenticationOptions {
AuthenticationType = "Cookies"
});
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions {
Authority = "https://localhost:44300/identity",
ClientId = "mvc",
RedirectUri = "https://localhost:46289/", //must be in server's Client.RedirectUris
ResponseType = "id_token",
SignInAsAuthenticationType = "Cookies"
});
【讨论】:
我遇到了这个问题。服务器中的 RedirectUris 条目几乎与客户端 Startup.Configuration 中的 RedirectUri 匹配;除了尾部的斜线。
https://localhost:46289/
不一样
https://localhost:46289
当我添加斜线时,我的登录页面出现了。
【讨论】:
我一直在解决同样的问题,但只是针对 Identity Server 进行身份验证(Google 是我接下来要解决的问题)。我看到了这个问题,因为客户端的范围没有在 Mvc 和服务器上设置。为了解决这个问题,我将作用域添加到(Mvc 客户端的)启动类中,如下所示:
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
Authority = "https://localhost:44301",
Scope = "openid profile email roles",
ClientId = "mvc",
RedirectUri = "https://localhost:44300/",
ResponseType = "id_token",
SignInAsAuthenticationType = "Cookies"
});
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = "Cookies"
});
}
}
..并且也在服务器的客户端列表中:
public static class Clients
{
public static IEnumerable<Client> Get()
{
return new[]
{
new Client
{
Enabled = true,
ClientName = "MVC Client",
ClientId = "mvc",
Flow = Flows.Implicit,
RequireConsent = true,
RedirectUris = new List<string>
{
"https://localhost:44300/"
},
PostLogoutRedirectUris = new List<string>
{
"https://localhost:44300/"
},
AllowedScopes = new List<string> {
Constants.StandardScopes.OpenId,
Constants.StandardScopes.Profile,
Constants.StandardScopes.Email,
Constants.StandardScopes.Roles
}
}
};
}
}
关于 OP 向 Google 提出的问题,可能值得在 Google Developer Console 中检查您的范围是否与您的应用设置所支持的范围相关。 Where can I find a list of scopes for Google's OAuth 2.0 API?
上有一篇关于受支持范围的好帖子希望有帮助:)
【讨论】:
看起来客户端(您希望可以使用 Google 登录的应用程序)未在客户端商店中注册。能否请您出示一下您的启动配置?
【讨论】:
就我而言,当我应该更改Clients.Get() 中的值,即服务器已配置的允许客户端。
一旦我修复了这些问题,我就能够将客户端和服务器分成两个应用程序,只有一些 NuGet 包和客户端应用程序中的 UseCookieAuthentication/UseOpenIdConnectAuthentication。
如果客户端未启用,重定向 uri 与列表中的一个不匹配(使用不区分大小写的精确匹配),如果请求的范围不在允许的范围列表中,如果请求的流,您会收到错误与允许的不匹配(每个客户端只能有一个)和/或客户端 ID 不匹配。
【讨论】: