有人可以帮我了解如何使用ASP.NET 5.0对Azure AD进行身份验证吗?我找到了Katana的这段代码,但我不知道ASP.NET 5.0中的等价物
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseWsFederationAuthentication(
new WsFederationAuthenticationOptions
{
Wtrealm = "http://myapps/testapp",
MetadataAddress = "https://login.windows.net/34g988bf-86f1-41af-91ab-2d7cd911db47/federationmetadata/2007-06/federationmetadata.xml"
});
答案 0 :(得分:0)
在ASP.NET 5.0中有一个基于cookie的身份验证的新实现,这些示例可以在官方MicroSoft ASP.NET Security GitHub page
上找到首先,您需要在project.json文件中添加身份验证库作为依赖项:
"dependencies": {
"Microsoft.AspNet.Server.IIS": "1.0.0-beta4",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta4",
"Microsoft.AspNet.Mvc": "6.0.0-beta4",
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-*",
看看以下几行:
using Microsoft.AspNet.Authentication.Cookies;
和
app.UseCookieAuthentication(options =>
{
options.AutomaticAuthentication = true;
});
app.Run(async context =>
{
if (string.IsNullOrEmpty(context.User.Identity.Name))
{
var user = new ClaimsPrincipal(new ClaimsIdentity(
new[]
{
new Claim(ClaimTypes.Name, "bob")
}
));
context.Authentication.SignIn(CookieAuthenticationDefaults.AuthenticationScheme,
user);
context.Response.ContentType = "text/plain";
await context.Response.WriteAsync("Hello First timer");
return;
}
context.Response.ContentType = "text/plain";
await context.Response.WriteAsync("Hello old timer");
});
这应该在MVC 6网络应用程序中的app.UseMvc()之前。 我希望这有帮助?如果这不符合您的要求,请告诉我,我会尝试澄清任何要点:)