C# 如何为IdentityServer3设置MVC客户端
我正在尝试使用IdentityServer3,因此我将查看官方示例。我创建了一个非常简单的授权服务器:C# 如何为IdentityServer3设置MVC客户端,c#,asp.net-mvc,identityserver3,C#,Asp.net Mvc,Identityserver3,我正在尝试使用IdentityServer3,因此我将查看官方示例。我创建了一个非常简单的授权服务器: namespace SimpleIdentityServer { public class Startup { public void Configuration(IAppBuilder app) { var options = new IdentityServerOptions {
namespace SimpleIdentityServer
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
var options = new IdentityServerOptions
{
Factory = new IdentityServerServiceFactory()
.UseInMemoryClients(Clients.Get())
.UseInMemoryScopes(Scopes.Get())
.UseInMemoryUsers(Users.Get()),
RequireSsl = false
};
app.UseIdentityServer(options);
}
}
}
这是我的内存用户:
new Client
{
ClientName = "MVC application",
ClientId = "mvc",
Enabled = true,
AccessTokenType = AccessTokenType.Jwt,
Flow = Flows.Implicit,
ClientSecrets = new List<Secret>
{
new Secret("secret".Sha256())
},
AllowedScopes = new List<string>
{
"openId",
"profile"
},
RedirectUris = new List<string>
{
"http://localhost:12261/"
}
}
这是一个带有Authorize属性的示例控制器操作:
[Authorize]
public ActionResult About()
{
ViewBag.Message = "Your application description page.";
return View();
}
但是,当我在mvc应用程序中返回home/about时,它会显示401错误,并且从serilog中可以看出,它甚至没有调用授权服务器 我认为可能发生的情况是您的OWIN管道没有执行。您是否可以尝试在启动类中设置断点,杀死IIS或IIS Express(无论您使用的是哪种),然后重新启动 如果是这种情况,那么IODC中间件不会捕获HTTP 401响应,因此不会将您重定向到IdentityServer实例
对此可能的解释是,在IIS上运行ASP.NET应用程序时,您没有包含启用OWIN的必要NuGet包。该软件包是Microsoft.Owin.Host.SystemWeb。您是否从Identity Server收到任何错误?假设您的identity server作为默认服务器运行,并绑定到/core/客户端中的权限应为。此外,您可能需要告诉客户端站点允许外部cookie:app.useexternalsignincookiefaultauthenticationtypes.ExternalCookie@NickBork实际上,我已经在一个自托管的控制台应用程序上实现了Identity Server:WebApp.Starthttp://localhost:47945. 无论如何,我没有得到任何错误。而且,我还没有在服务器的启动配置方法中添加任何映射。@NickBork app.UseExternalSignInCookieDefaultAuthenticationTypes.Exter纳库奇;没有改变任何事情。
[Authorize]
public ActionResult About()
{
ViewBag.Message = "Your application description page.";
return View();
}