[英]Can I use SharePoint to authenticate users on a separately hosted website?
[英]how can I use a Microsoft Account to authenticate to my website
我有一个需要用户身份的网站,我真的不想让他们创建另一个他们必须记住的用户名/密码组合
是否有SDK允许从Microsoft帐户进行身份验证?
这很简单,因为ASP.NET 4.5网站的默认空模板显示了如何使用google / facebook / liveid / twitter进行OAuth2身份验证。
http://www.asp.net/aspnet/overview/aspnet-45/oauth-in-the-default-aspnet-45-templates
查看Principal Context类。 您可以使用localhost(计算机)或域上下文创建它,并使用ValidateCrentials(字符串用户名,字符串密码)方法使用Windows凭据进行身份验证。
http://msdn.microsoft.com/en-us/library/bb154889.aspx
这是我在我的网站上使用它的方式。 (把它放在你的身份验证控制器的POST方法或其他东西)
下面的代码将使用用户名“bob”或“localhost \\ bob”或“DOMAIN \\ bob”等,并获取正确的PrincipalContext用于验证用户。 注意:这里不区分大小写。
public bool ValidateCredentials(string username, System.Security.SecureString password)
{
string domain = Environment.MachineName;
if (username.Contains("\\"))
{
domain = username.Split('\\')[0];
username = username.Split('\\')[1];
}
if (domain.Equals("localhost", StringComparison.CurrentCultureIgnoreCase))
domain = Environment.MachineName;
if (domain.Equals(Environment.MachineName, StringComparison.CurrentCultureIgnoreCase))
using (PrincipalContext context = new PrincipalContext(ContextType.Machine))
{
return context.ValidateCredentials(username, password.ToUnsecureString());
}
else
using(PrincipalContext context = new PrincipalContext(ContextType.Domain))
{
//return context.ValidateCredentials(domain + "\\" + username, password.ToUnsecureString());
return context.ValidateCredentials(username, password.ToUnsecureString());
}
}
Microsoft提供Live Connect SDK,用于将Microsoft服务集成到您的应用程序中,包括Microsoft帐户身份提供程序。
服务器端方案中有一个特定示例,它应该涵盖集成所需的全部内容。
你的意思是从活动目录Windows帐户? 如果是这样,您可以使用Windows身份验证,只需让索引页面自动签名。
http://msdn.microsoft.com/en-us/library/ff647405.aspx
在代码隐藏文件中使用以下命令以获取有关登录的相关信息:
System.Security.Principal.WindowsIdentity.GetCurrent().Name
User.Identity.IsAuthenticated
User.Identity.AuthenticationType
User.Identity.Name
微软的变更/品牌重塑/弃用/死链接给我带来了疯狂。 在任何情况下,我发现的最新版本是“Microsoft帐户外部登录”,可以首先在Microsoft Developer Portal上设置 。
我在https://docs.microsoft.com/en-us/aspnet/core/security/authentication/social/microsoft-logins上找到了一个解释如何为.Net Core做这个的指南,虽然是上半部分(例如设置)重定向URI)不是特定于框架的。
我还在https://github.com/aspnet/Security/blob/master/src/Microsoft.AspNetCore.Authentication.MicrosoftAccount/MicrosoftAccountOptions.cs上找到了.Net Core的相关源代码,其中显示了一些声明(用户)检索的详细信息):
ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "id");
ClaimActions.MapJsonKey(ClaimTypes.Name, "displayName");
ClaimActions.MapJsonKey(ClaimTypes.GivenName, "givenName");
ClaimActions.MapJsonKey(ClaimTypes.Surname, "surname");
ClaimActions.MapCustomJson(ClaimTypes.Email,
user => user.Value<string>("mail") ?? user.Value<string>("userPrincipalName"));
最新版本的.Net Core的支持告诉我,这个外部登录API仍然有效。 我还没有测试它们,如果我要进行这种登录集成,我会更新。
答案已过期 - 微软已更改链接
终于找到了类似于Facebook / Google身份验证的Javascript库
https://msdn.microsoft.com/en-au/library/ff748792.aspx
和
http://isdk.dev.live.com/dev/isdk/ISDK.aspx?category=scenarioGroup_core_concepts&index=0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.