-1
我正在尝试使用IdentityServer3,因此我将通过官方示例。我已经创建了一个授权服务器,这是非常简单的:如何为IdentityServer3设置MVC客户端
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/"
}
}
现在,我想使用上述服务器的MVC应用程序的用户进行身份验证,所以我这样做:
public void Configuration(IAppBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = "Cookies"
});
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
Authority = "http://localhost:47945/",
ClientId = "mvc",
RedirectUri = "http://localhost:12261/",
ResponseType = "id_token",
SignInAsAuthenticationType = "Cookies"
});
}
这是与Authorize
属性标注的样本控制器动作:
[Authorize]
public ActionResult About()
{
ViewBag.Message = "Your application description page.";
return View();
}
但是,当我回家/关于我的mvc应用程序时,它显示我401错误,它似乎(从serilog)它甚至不会调用授权服务器。
您是否从Identity Server获取任何错误?假设您的身份服务器作为默认运行并且绑定到/ core /,您的客户端中的Authority应该是http:// localhost:47945/core /。另外,您可能需要告诉客户端网站允许使用外部Cookie: app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); –
@NickBork实际上,我已经在自托管的控制台应用程序上实现了Identity Server:WebApp.Start(“http:// localhost:47945”)'。无论如何,我没有得到任何错误。而且,我还没有添加任何映射(在服务器的启动配置方法中)。 –
mok
@NickBork'app.UseExternalSignInCookie(DefaultAuthenticationTypes.Exter nalCookie); '没有改变任何东西。 – mok