asp.net-mvc – Identity Server 3 – 客户端应用程序未知或未经授权

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

这是我的客户:

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"
                }
            }
        };
    }
}

这是我的Web应用程序启动:

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

        app.USEOpenIdConnectAuthentication(new OpenIdConnectAuthenticationoptions
        {
            Authority = UrlManager.AuthenticationService + "identity",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流程,则应用程序可以正常运行.

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

解决方法

客户端已配置为授权代码

Flow = Flows.AuthorizationCode

但是启动时的响应类型设置为混合流.

ResponseType = “code id_token”

尝试将此更改为

ResponseType = “code” (or Change the Flow type to Hybrid)

下面是ResponseType和相应的Flow列表

相关文章

这篇文章主要讲解了“WPF如何实现带筛选功能的DataGrid”,文...
本篇内容介绍了“基于WPF如何实现3D画廊动画效果”的有关知识...
Some samples are below for ASP.Net web form controls:(fr...
问题描述: 对于未定义为 System.String 的列,唯一有效的值...
最近用到了CalendarExtender,结果不知道为什么发生了错位,...
ASP.NET 2.0 page lifecyle ASP.NET 2.0 event sequence cha...