• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Coding Still

  • Home
  • About

LinkedIn login for your website

July 24, 2015 By _tasos 7 Comments

In this article we will see how we can implement LinkedIn login for your web application. We will use the JavaScript SDK but LinkedIn has more than one SDKs available for your language of choice.

The article consists of two parts. The first part we will be the implementation of the login process while the second part will about getting the required credentials.

The code consists of two <script> tags The first contains the refernce 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.

After creating your Application go to Authentication. The Client ID is the API Key required in our example. Then, go to JavaScript and declare which domains will be using your application. You can add localhost but make sure to include the port number (if any).

Note: As mentioned in the documentation, the JavaScript SDK does is not compatible with iOS 5+. This means the above code might not work in iPad and iPhone.

Filed Under: JavaScript Tagged With: OAuth, Social media

Reader Interactions

Comments

  1. Ahmed s says

    July 26, 2016 at 12:25

    “You need to authenticate in order to use ‘me’ or ‘~’ as a valid profile identifier”.

    I’m getting this error..What should I do.?.

    Reply
    • _tasos says

      July 26, 2016 at 19:48

      Perhaps you are calling getProfileData() directly? You should call liLogin(), and that function has getProfileData() as a callback.

      Reply
  2. Mac says

    August 26, 2016 at 15:56

    Hey thanks … its worked well … but now I am searhing for getting the access token to the console.
    Thanks

    Reply
    • _tasos says

      August 28, 2016 at 10:12

      Take a look here.

      If you put in the console.debug("oauth token:" + IN.ENV.auth.oauth_token); in the getProfileData(...) function you will get the token.

      Reply
  3. Wolfred says

    June 27, 2017 at 02:28

    Thank you your code is very usefull… Do you have any example using IN.User.logout(); … I got Refused to get unsafe header.. when I tried to use it

    Reply
  4. Pankaj says

    December 25, 2019 at 11:53

    not working

    Reply
    • _tasos says

      January 19, 2020 at 19:51

      Hi PanKaj,

      The code here is for the v1 of the LinkedIn API which is now deprecated.

      Reply

Leave a Reply to _tasos Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Categories

  • .NET Development
  • ASP.NET
  • Databases
  • Fun
  • IIS
  • JavaScript
  • Web Development

Tags

.NET Core Android ANTLR ASP.NET Ajax ASP.NET Core ASP.NET MVC ASP.NET Web Forms AWS Bouncy Castle Chartjs cli Client info detection Comic Continuous integration CSS Data backup Date handling Firebase Firefox addons Github HigLabo HTML5 Image manipulation jQuery JWT MySQL Nodejs Nuget OAuth Objectionjs OOP openssl Oracle ORM PHP Regular expressions SEO Social media SQL SQL Server UI/UX Url rewriting Videos Visual Studio Web design

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Secondary Sidebar

Archives

  • July 2020
  • March 2020
  • August 2019
  • December 2018
  • November 2018
  • February 2018
  • August 2016
  • June 2016
  • May 2016
  • February 2016
  • January 2016
  • August 2015
  • July 2015
  • October 2014
  • July 2014
  • November 2013
  • April 2013
  • February 2013
  • January 2013
  • December 2012
  • November 2012
  • August 2012
  • May 2012
  • February 2012
  • December 2011
  • October 2011
  • September 2011
  • August 2011
  • July 2011
  • May 2011
  • April 2011
  • March 2011
  • February 2011
  • January 2011
  • December 2010
  • November 2010
  • October 2010
  • September 2010
  • August 2010
  • July 2010

Footer

Recent Posts

  • Anatomy of an Objection.js model
  • Check your RSA private and public keys
  • Round functions on the Nth digit
  • Send FCM Notifications in C#
  • Jwt Manager
  • Things around the web #5
  • Query JSON data as relational in MySQL
  • Create and sign JWT token with RS256 using the private key
  • Drop all database objects in Oracle
  • Create and deploy a Nuget package

Latest tweets

  • Geekiness Intensifies.. NASA used Three.js to render a real-time simulation of this week's NASA rover landing on M… https://t.co/orgkXnYj9O February 19, 2021 18:12
  • Things I Wished More Developers Knew About Databases https://t.co/h4gfq6NJgo #softwaredevelopment #databases May 3, 2020 12:52
  • How a Few Lines of Code Broke Lots of Packages https://t.co/p7ZSiLY5ca #javascript May 3, 2020 12:48
  • Can someone steal my IP address and use it as their own? https://t.co/HoQ7Z3BG69 January 24, 2020 13:27
  • Organizational complexity is the best predictor of bugs in a software module https://t.co/aUYn9hD4oa #softwaredevelopment January 13, 2020 08:24
  • http://twitter.com/codingstill

Misc Links

  • George Liatsos Blog
  • Plethora Themes
  • C# / VB Converter
  • Higlabo: .NET library for mail, DropBox, Twitter & more

Connect with me

  • GitHub
  • LinkedIn
  • RSS
  • Twitter
  • Stack Overflow

Copyright © 2021 · eleven40 Pro on Genesis Framework · WordPress · Log in