我收到错误消息“客户端应用程序未知或未被授权。” 访问我网站的保护区时。
这是我的客户:
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",
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);
}
}
当我访问专用时,我得到一个Identity Server 3屏幕,该屏幕显示错误消息“客户端应用程序未知或未被授权。”。
我已经读到这可能来自重定向URI中的不匹配,但据我所知是正确的。我不知道还有什么原因。如果我将流程更改为隐式,但我想实现AuthorizationCode流程,则该应用程序将正常运行。
该文档似乎也没有对此有所说明。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句