使用Azure AD ASP.NET 5.0进行身份验证?
问题描述:
有人可以帮助我如何使用ASP.NET 5.0对Azure AD进行身份验证吗?我发现这个武士刀代码,但我不知道在ASP.NET相当于5.0使用Azure AD 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"
});
答
有在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");
});
这应该在6 MVC的Web应用程序app.UseMvc()面前。 我希望这有助于?让我知道如果这不符合您的要求,我会尽力澄清任何要点:)
对此有何帮助?谢谢 – 2015-02-12 06:24:42
通过我们的电子邮件线程,这将很快* *很快*。多久会很快? *很快 :) – Eilon 2015-02-13 22:19:17