简体   繁体   English

如何使用Microsoft帐户对我的网站进行身份验证

[英]how can I use a Microsoft Account to authenticate to my website

I have a website where a users identity is needed, I'd really prefer not to make them create yet another username/password combo that they have to remember 我有一个需要用户身份的网站,我真的不想让他们创建另一个他们必须记住的用户名/密码组合

are there SDK's for allowing authentication from an Microsoft account? 是否有SDK允许从Microsoft帐户进行身份验证?

That's rather easy as a default empty template of an ASP.NET 4.5 website shows how to have OAuth2 authentication with google/facebook/liveid/twitter. 这很简单,因为ASP.NET 4.5网站的默认空模板显示了如何使用google / facebook / liveid / twitter进行OAuth2身份验证。

http://www.asp.net/aspnet/overview/aspnet-45/oauth-in-the-default-aspnet-45-templates http://www.asp.net/aspnet/overview/aspnet-45/oauth-in-the-default-aspnet-45-templates

Check out the Principal Context class. 查看Principal Context类。 You can create it using a localhost (Machine) or domain context and use the ValidateCrentials(string username, string password) method to authenticate using Windows credentials. 您可以使用localhost(计算机)或域上下文创建它,并使用ValidateCrentials(字符串用户名,字符串密码)方法使用Windows凭据进行身份验证。

http://msdn.microsoft.com/en-us/library/bb154889.aspx http://msdn.microsoft.com/en-us/library/bb154889.aspx

Here's how I've used it in my website. 这是我在我的网站上使用它的方式。 (Put this in a POST method of your authentication controller or something) (把它放在你的身份验证控制器的POST方法或其他东西)

The code below will take a username say "bob" or "localhost\\bob" or "DOMAIN\\bob" etc., and get the right PrincipalContext for authenticating the user. 下面的代码将使用用户名“bob”或“localhost \\ bob”或“DOMAIN \\ bob”等,并获取正确的PrincipalContext用于验证用户。 NOTE: it's case insensitive here. 注意:这里不区分大小写。

        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 provides the Live Connect SDK for integration Microsoft services into your applications, including the Microsoft Accounts identity provider. Microsoft提供Live Connect SDK,用于将Microsoft服务集成到您的应用程序中,包括Microsoft帐户身份提供程序。

There is a specific example on Server-Side Scenarios which should cover all you need to get integrated. 服务器端方案中有一个特定示例,它应该涵盖集成所需的全部内容。

Do you mean from an active directory windows account? 你的意思是从活动目录Windows帐户? If so you could use windows authentication and just have the index page sign them in automatically. 如果是这样,您可以使用Windows身份验证,只需让索引页面自动签名。

http://msdn.microsoft.com/en-us/library/ff647405.aspx http://msdn.microsoft.com/en-us/library/ff647405.aspx

Use the following commands in your code behind file to get the relevant information for signing in: 在代码隐藏文件中使用以下命令以获取有关登录的相关信息:

System.Security.Principal.WindowsIdentity.GetCurrent().Name
User.Identity.IsAuthenticated
User.Identity.AuthenticationType
User.Identity.Name

The amount of changes / rebranding / deprecation / dead links from Microsoft drives me crazy. 微软的变更/品牌重塑/弃用/死链接给我带来了疯狂。 In any case, the latest version of this from what I've found is "Microsoft Account external login", which can be first set up on the Microsoft Developer Portal . 在任何情况下,我发现的最新版本是“Microsoft帐户外部登录”,可以首先在Microsoft Developer Portal上设置

I found a guide that explains how to do this for .Net Core at https://docs.microsoft.com/en-us/aspnet/core/security/authentication/social/microsoft-logins , though the first half (eg setting the Redirect URI) isn't framework-specific. 我在https://docs.microsoft.com/en-us/aspnet/core/security/authentication/social/microsoft-logins上找到了一个解释如何为.Net Core做这个的指南,虽然是上半部分(例如设置)重定向URI)不是特定于框架的。

I also found some relevant source code for .Net Core at https://github.com/aspnet/Security/blob/master/src/Microsoft.AspNetCore.Authentication.MicrosoftAccount/MicrosoftAccountOptions.cs , which shows some of the Claims (user details) that are retrieved: 我还在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"));

The support from the latest version of .Net Core suggests to me that this external login API still works. 最新版本的.Net Core的支持告诉我,这个外部登录API仍然有效。 I haven't tested them out yet, I will update if I get to do this login integration. 我还没有测试它们,如果我要进行这种登录集成,我会更新。

Answer Expired - Microsoft had changed there links 答案已过期 - 微软已更改链接


Finally found the Javascript library to do it similar to Facebook/Google Authentication 终于找到了类似于Facebook / Google身份验证的Javascript库

https://msdn.microsoft.com/en-au/library/ff748792.aspx https://msdn.microsoft.com/en-au/library/ff748792.aspx

And

http://isdk.dev.live.com/dev/isdk/ISDK.aspx?category=scenarioGroup_core_concepts&index=0 http://isdk.dev.live.com/dev/isdk/ISDK.aspx?category=scenarioGroup_core_concepts&index=0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以使用SharePoint对单独托管的网站上的用户进行身份验证吗? - Can I use SharePoint to authenticate users on a separately hosted website? 如何绕过我的 ASP.NET 帐户中的“使用本地帐户登录”页面? - How can I bypass the "Use a local account to log in" page in my ASP.NET account? 如何在Visual Studio中的网站上使用控制台应用程序? - How can I use a console application with my website in Visual Studio? Asp.net如何使用paypal电子邮件ID和密码在我的网站上获取paypal帐户的交易历史记录 - Asp.net How can i get the transaction history of paypal account on my website using paypal email id and password 如果用户没有我的网站,我该如何自动下载我使用的字体? - How can my users automatically download the font I use for my website if they don't have it? 看不到我在网站上使用的图片 - Can't see my picture that I use in my webSite 使用Microsoft帐户登录网站 - Signing into a website using Microsoft Account 我可以使用键盘快捷键来使用我的网站吗? - Can I use keyboard short cuts to use my website 我如何保护我的网站 - how can i protect my website 如何部署我准备好的网站? - How can I deploy my ready website?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM