【问题标题】:Identity Server 3 - The client application is not known or is not authorizedIdentity Server 3 - 客户端应用程序未知或未经授权
【发布时间】:2016-10-06 07:00:32
【问题描述】:

我收到错误消息“客户端应用程序未知或未经授权。”访问我网站的受保护区域时。

这是我的客户:

public static class Clients
{
    public static IEnumerable<Client> Get()
    {
        return new[]
        {
            new Client
            {
                Enabled = true,
                ClientName = "Web Application",
                ClientId = "webapplication",
                Flow = Flows.AuthorizationCode,

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

                RedirectUris = new List<string>
                {
                    UrlManager.WebApplication
                },
                PostLogoutRedirectUris = new List<string>
                {
                    UrlManager.WebApplication
                },

                AllowedScopes = new List<string>
                {
                    Constants.StandardScopes.OpenId,
                    Constants.StandardScopes.Profile,
                    Constants.StandardScopes.Email,
                    Constants.StandardScopes.Roles,
                    Constants.StandardScopes.OfflineAccess,
                    "read",
                    "write"
                }
            }
        };
    }
}

这是我的网络应用程序启动:

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = "Cookies"
        });

        app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
        {
            Authority = UrlManager.AuthenticationService + "identity",

            ClientId = "webapplication",
            Scope = "openid profile",
            ResponseType = "code id_token",
            RedirectUri = UrlManager.WebApplication,

            SignInAsAuthenticationType = "Cookies"
        });
    }
}

这是我的身份验证服务(安装了 IDS3)启动:

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        app.Map("/identity", idsrvApp =>
        {
            idsrvApp.UseIdentityServer(new IdentityServerOptions
            {
                SiteName = "Authentication Service - Embedded IdentityServer",
                SigningCertificate = Certificate.LoadCertificate(),

                Factory = new IdentityServerServiceFactory()
                            .UseInMemoryUsers(Users.Get())
                            .UseInMemoryClients(Clients.Get())
                            .UseInMemoryScopes(Scopes.Get())
            });
        });
    }
}

这是 UrlManager:

public static class UrlManager
{
    public static string WebApplication
    {
        get { return "https://localhost:44381/"; }
    }

    public static string AuthenticationService
    {
        get { return "https://localhost:44329/"; }
    }
}

这是我的家庭控制器:

public class HomeController : Controller
{
    public ActionResult Index()
    {
        return View();
    }

    [Authorize]
    public ActionResult Private()
    {
        return View((User as ClaimsPrincipal).Claims);
    }
}

当我访问 Private 时,我看到一个 Identity Server 3 屏幕,显示错误消息“客户端应用程序未知或未授权。”。

我已经读到这可能来自重定向 URI 中的不匹配,但据我所知,我的是正确的。我不知道还有什么可能导致它。如果我将流程更改为隐式但我想实现 AuthorizationCode 流程,则应用程序可以完美运行。

文档似乎也没有说明这一点。

【问题讨论】:

    标签: asp.net-mvc oauth oauth-2.0 openid-connect identityserver3


    【解决方案1】:

    如果您的 ClientUri 域名与您的 ClientRedirectUri 域名不匹配,也会发生这种情况。

    看到我遇到这个问题是因为缺少“www”。在客户端重定向 uri 中。

    问题 - ClientRedirectUri 没有“www”。在里面:

    ClientUri: https://www.mydomainname.co.uk

    ClientRedirectUri: https://mydomainname.co.uk/umbraco/surface/UmbracoIdentityAccount/ExternalLoginCallback

    解决方案 - ClientRedirectUri 有“www”。在其中,就像 ClientUri 所做的那样:

    ClientUri: https://www.mydomainname.co.uk

    ClientRedirectUri: https://www.mydomainname.co.uk/umbraco/surface/UmbracoIdentityAccount/ExternalLoginCallback

    【讨论】:

      【解决方案2】:

      我收到了这个错误,问题是 RedirectUri. 在授权服务器中是 http://localhost:56840/,在 Web 应用程序中是 http://localhost:56840。 请注意网址末尾缺少的“/”。

      【讨论】:

      • 我很想知道你是如何纠正这个问题的,如果它是真正的错误的话。干杯
      【解决方案3】:

      客户端已配置为授权码流

      Flow = Flows.AuthorizationCode

      但是启动中的响应类型设置为混合流。

      ResponseType = "code id_token"

      尝试将其更改为

      ResponseType = "code"(或将 Flow 类型更改为 Hybrid)

      下面是ResponseType列表和对应的Flow

      【讨论】:

      猜你喜欢
      • 2020-01-11
      • 2019-07-25
      • 1970-01-01
      • 2017-02-08
      • 2015-02-01
      • 2018-07-19
      • 2016-08-03
      • 2013-08-03
      • 1970-01-01
      相关资源
      最近更新 更多