Using LinkedIn JavaScript API for User Authentication and Profile Retrieval

Using LinkedIn JavaScript API for User Authentication and Profile Retrieval

Learn how to ingrate LinkedIn authentication with your own webstek using the LinkedIn JavaScript API.

Introduction

Integrating third-party sign-in with a webstek is fairly common thesis days. Just like Facebook and Twitter, LinkedIn too permits you to ingrate LinkedIn authentication with your own webstek. One elementary way to achieve such an integration is to use LinkedIn JavaScript API. Using this API you can authenticate a user with their LinkedIn credentials and also retrieve their profile and connection information. Merienda retrieved you can use that information to integrate LinkedIn authentication with your webstek’s security and membership framework.

Creating a LinkedIn Application

The very first step ter integrating LinkedIn authentication with your webstek is to create a LinkedIn application. To do so, go to LinkedIn Developer Network and create a fresh application. The following figure shows the main application creation pagina.

Main Application Creation Pagina

While there are many mandatory fields of the above form, the sections highlighted above are significant. Especially, notice the Webstek URL and Default Scope entries. The Webstek URL should contain a URL that identifies your webstek. During development you can use a localhost based path such spil http://localhost:12345. However, merienda the development is overheen you should switch it to a positivo webstek address. The default scope area is used to indicate the default set of permissions that a user voorwaarde grant to the application being created. Ter the above figure a user voorwaarde share his basic profile information with the application being created.

There is another section (not shown ter the above figure) titled JavaScript API Domains that contains one or more webstek URLs. For the sake of this example you can use a localhost based URL ter that textbox.

Getting an Application API Key

Merienda you inject all the required fileds, klapper Save to create the application. Upon successful creation you will also be shows details such spil API Key and Secret Key. Ter this example API Key is sufficient and you should note it down somewhere before going ahead. The following figure shows the area where API Key is shown:

Loading LinkedIn JavaScript Library

Now that you have created a LinkedIn application, you can proceed to integrating it with your webstek. Create a fresh webstek te your beloved instrument / IDE (say Visual Studio) and add an HTML pagina to the webstek. Integrating LinkedIn authentication and retrieving user profile requires that you flow the LinkedIn JavaScript framework into your webpagina. This can be done by incorporating the following markup te the webpagina.

The above markup consists of a &lt,script&gt, block that points to http://verhoging.linkedin.com/ter.js – the core LinkedIn JavaScript framework. Notice that inwards the block you need to place the api_key you obtained te the previous section. When the web pagina geysers, the LinkedIn JavaScript framework checks whether the URL spil mentioned ter the application’s configuration and that of the requesting pagina matches or not. If the API key is invalid you will get a JavaScript te the browser’s JavaScript console (see below).

The authorize setting controls whether a user should sign-in to the application even if he has previously granted permissions to the application under consideration. Set authorize to true.

Displaying the Sign-in Button

A webstek with LinkedIn authentication will usually present a button to the end user that hints that the user is supposed to supply his LinkedIn credentials te order to sign-in. To render such a button you can add the following script ter the web pagina.

Setting the type attribute to ter/Login does the trick and you get a sign-in button like this:

You can place the above &lt,script&gt, block anywhere you wish to display the sign-in button. When a user clicks this Sign-in button, another browser window opens that shows the LinkedIn sign-in pagina where he can supply his LinkedIn credentials (see below).

Linked-In Sign-In Pagina

The LinkedIn authentication is based on OAuth Two and is treated by LinkedIn. If the user supplies valid credentials he is signed-in to LinkedIn and the sign-in window is closed.

Wiring Auth Event Handler

Signing-in with LinkedIn credentials is just one part of the story. Merienda a user is successfully authenticated you may want to get notified so that you can proceed to retrieve his profile details. To get such a notification you can wire an event handler to the auth event. To wire an auth event handler, very first you need to treat the explosion event of the LinkedIn JavaScript framework and merienda the framework is loaded link the auth event handler. The following lump of code shows how this can be done:

The above markup sets the onLoad event handler to a JavaScript function named – OnLinkedInFrameworkLoad. The OnLinkedInFrameworkLoad() function looks like this:

The OnLinkedInFrameworkLoad() function wires the auth event handler to another JavaScript function – OnLinkedInAuth(). Notice that this event is wired using the Ter object of the framework. The OnLinkedInAuth() function is responsible for retrieving the user’s profile and is discussed te the next section.

Retrieving a User Profile

Spil mentioned earlier OnLinkedInAuth() function is called when a user successfully signs-in to the system. Merienda a user is authenticated you can go ahead and read his profile details. To grab the profile details you use the “mij” keyword. The following code shows how this is done.

The above code passes ShowProfileData() – a custom-made JavaScript function – to the result() call. This way when the profile information is retrieved it is passed to the ShowProfileData() function spil a parameter.

The ShowProfileData() function is shown below:

Spil you can see the ShowProfileData() functions receives the profile’s parameter. To get the profile of the “mij” user (current user) you use profiles.values[0] and store it ter a member variable. You can then access various lumps of information such spil id, firstName, lastName, pictureUrl and headline. There are many more chunks of information that you can retrieve depending on the permissions granted by a user. A list of all the possible fields can be obtained here. What to do with the profile gegevens retrieved depends on your need. For example, you may store thesis details te your webstek’s database or take the user to your webstek’s registration pagina and pre-populate certain fields.

Summary

LinkedIn JavaScript API permits you to integrate LinkedIn authentication with your webstek. You can also retrieve the user profile using the API. There are many other uses of the API spil described ter the official documentation. This article illustrated a basic authentication and profile retrieval using the JavaScript API.

3 thoughts on “Using LinkedIn JavaScript API for User Authentication and Profile Retrieval

  1. Verification Requirements: Binance by default permits you to withdrawal the omschrijving of Two BTC / day, without requiring any private information. You can increase this to 100 BTC / day by completing verification. Both Bittrex and yobit require verification for any withdrawals. Keep te mind yobit’s poor customer support may severely delay your verification.

  2. Customer Support: While none of thesis exchanges have anywhere close to flawless customer support, yobit seems to be particularly bad te this area. Many yobit users have practices support tickets taking numerous months. Binance and Bittrex support is usually treated te a more reasonable time framework of a few weeks max.

Leave a Reply

Your email address will not be published. Required fields are marked *