Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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).

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?

like image 614
yazz.com Avatar asked Apr 29 '12 15:04

yazz.com


People also ask

How do I integrate LinkedIn API on my website?

Login to the LinkedIn Developer portal. Click My Apps from the top of the page and select Create App. Complete the app details and add your company page. For Self-Serve, complete all the steps and then click the Create App button at the bottom of the page.

How do I use LinkedIn API in Python?

HTTP API exampleSet LINKEDIN_API_KEY and LINKEDIN_API_SECRET, configure your app to redirect to http://localhost:8080/code, then execute: http_api.py. Visit http://localhost:8080 in your browser, curl or similar. A tab in your browser will open up, give LinkedIn permission there.


1 Answers

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

<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.

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.

<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.

like image 113
Abdo-Host Avatar answered Sep 25 '22 01:09

Abdo-Host