如何使用 Linkedin Javascript API 作为我自己网站的登录名?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10373497/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 09:38:43  来源:igfitidea点击:

How can I use the Linkedin Javascript API as a login for my own website?

javascriptauthenticationlinkedin

提问by Yazz.com

I would like to use the linkedin javascript API as a way to login to my website as it seems far more end user friendly than using OAuth (ie: nicer to use with just a small popup to log into linked in).

我想使用linkedin javascript API 作为登录我的网站的一种方式,因为它似乎比使用OAuth 对最终用户友好得多(即:使用小弹出窗口登录链接更好)。

How can i use the information returned by linked in to securely log a user into my own website so that it can't be forged? Or do I need to provide an extra password that a user must enter?

如何使用链接返回的信息安全地将用户登录到我自己的网站,使其无法被伪造?或者我是否需要提供用户必须输入的额外密码?

采纳答案by ErikP

From the horses mouth: https://developer.linkedin.com/documents/sign-linkedinA general overview: http://thinlight.org/2011/08/07/using-facebook-and-other-sites-as-user-authentication-system/

来自马口:https: //developer.linkedin.com/documents/sign-linkedin概述:http: //thinlight.org/2011/08/07/using-facebook-and-other-sites-as-用户认证系统/

I'm not positive, but I think you're confusing what Oauth is. There's plenty of Oauth plugins for various CMS/languages that integrate seamlessly (with a little effort) - so the end user experience is that "click to login"

我并不乐观,但我认为您对 Oauth 是什么感到困惑。有大量适用于各种 CMS/语言的 Oauth 插件可以无缝集成(只需稍加努力) - 所以最终用户体验是“点击登录”

回答by Abdo-Host

The code consists of two <script>tags. The first contains the reference to the LinkedIn library and the declaration of the API Key.

代码由两个<script>标签组成。第一个包含对 LinkedIn 库的引用和 API 密钥的声明。

<script type="text/javascript" src="//platform.linkedin.com/in.js">
    api_key: <LinkedIn API Key>
</script>

The second tag has the required functionality. The liLogin() function will called when the user clicks on the Login with LinkedIn button. There you define the scope of data that your application requires.

第二个标签具有所需的功能。liLogin() 函数将在用户单击 Login with LinkedIn 按钮时调用。您可以在此处定义应用程序所需的数据范围。

The getProfileData() function is called after authentication and makes a second call to get the requested data. As you can see, you declare which data you want in your response.

getProfileData() 函数在身份验证后调用,并进行第二次调用以获取请求的数据。如您所见,您在响应中声明了您想要的数据。

<script>
    var liLogin = function() { // Setup an event listener to make an API call once auth is complete
        IN.UI.Authorize().params({"scope":["r_basicprofile", "r_emailaddress"]}).place();
        IN.Event.on(IN, 'auth', getProfileData);
    }

    var getProfileData = function() { // Use the API call wrapper to request the member's basic profile data
        IN.API.Profile("me").fields("id,firstName,lastName,email-address,picture-urls::(original),public-profile-url,location:(name)").result(function (me) {
            var profile = me.values[0];
            var id = profile.id;
            var firstName = profile.firstName;
            var lastName = profile.lastName;
            var emailAddress = profile.emailAddress;
            var pictureUrl = profile.pictureUrls.values[0];
            var profileUrl = profile.publicProfileUrl;
            var country = profile.location.name;
        });
    }
</script>

To get a LinkedIn API Key go to LinkedIn Developers. Go to My Apps and then click Create Application.

要获取 LinkedIn API 密钥,请访问LinkedIn Developers。转到我的应用程序,然后单击创建应用程序。