logo

NJP

Sign in with LinkedIn and Share with LinkedIn using Service Portal Pages

Import · Jun 15, 2018 · article

Hello All,

I recently posted a article on LikedIn integration with ServiceNow, now I'll share my POC details of LinkedIn integration with Service Portal. Here are the steps below...

1. Create LinkedIn App on https://www.linkedin.com/developer/apps

Once you save your configuration, your application will be assigned a unique "Client ID" (otherwise known as Consumer Key or API key) and "Client Secret" value. Make note of these values — you will need to integrate them into the configuration files or the actual code of your application, for example:

image

2. Add JavaScript Settings in LinkedIn App Page

LinkedIn's JavaScript SDK is a convienent way to enable LinkedIn integrations within your websites and web-based applications, without the need for any back-end programming. The major benefits of using the SDK include:

  • Easy authentication of LinkedIn members via functions that abstract all of the complexity of the authentication process away from you.
  • A convienent generic API call wrapper that allows you to make authenticated REST API calls.

image

3. Create a Portal Widget

Navigation: Service Portal -> Widgets - New

Use complete code in HTML section of the widget:

<!-- Initialize the SDK in your webpage--></p> <p>api_key: <strong>Client id from step #1</strong></p> <p>onLoad: onLinkedInLoad authorize: true</p> <p>

<!-- Setup an event listener to make an API call once auth is complete --> function onLinkedInLoad() { IN.Event.on(IN, &quot;auth&quot;, getProfileData);</p> <p>}</p> <p>// Use the API call wrapper to request the member&#39;s profile data function getProfileData() { IN.API.Profile(&quot;me&quot;).fields(&quot;id&quot;, &quot;first-name&quot;, &quot;last-name&quot;, &quot;headline&quot;, &quot;location&quot;, &quot;picture-url&quot;, &quot;public-profile-url&quot;, &quot;email-address&quot;).result(displayProfileData).error(onError);</p> <p>}</p> <p>// Handle the successful return from the API call function displayProfileData(data){ var user = data.values[0]; document.getElementById(&quot;picture&quot;).innerHTML = &#39;<img src="'+user.pictureUrl+'" />&#39;; document.getElementById(&quot;name&quot;).innerHTML = user.firstName+&#39; &#39;+user.lastName; document.getElementById(&quot;intro&quot;).innerHTML = user.headline; document.getElementById(&quot;email&quot;).innerHTML = user.emailAddress; document.getElementById(&quot;location&quot;).innerHTML = user.location.name; document.getElementById(&quot;link&quot;).innerHTML = &#39;<a href="'+user.publicProfileUrl+'" target="\_blank">Visit profile</a>&#39;;</p> <p>document.getElementById(&#39;profileData&#39;).style.display = &#39;block&#39;;</p> <p>}</p> <p>// Handle an error response from the API call function onError(error) { console.log(error);</p> <p>}</p> <p>// Destroy the session of linkedin function logout(){ IN.User.logout(removeProfileData); location.reload();</p> <p>}</p> <p>// Remove profile data from page function removeProfileData(){ document.getElementById(&#39;profileData&#39;).remove(); }</p> <p>

<!-- To Display User Profie Information -->

Logout

<!-- To Get the Share Button-->

4. Create a Portal Page: Add the above created (#3 Widget) to this page, It looks like below

image

5. Get the Access Toke with Login: Once user click on the “Sign in with LinkedIn” button it redirects to below page to authenticate the user access.

image

6. Result: Upon successful login it redirects to a result page where you can see the profile data along with Share button.

image

7. LinkedIn Share : If user clicks on “Share” button it opens a popup page like below:

image

That's it!!!! Hope it clear and helps you to integrate with LinkedIn.

Labels:

image

View original source

https://www.servicenow.com/community/developer-articles/sign-in-with-linkedin-and-share-with-linkedin-using-service/ta-p/2326671