Skip to content

Instantly share code, notes, and snippets.

@gauravtiwari
Created November 19, 2016 11:29
Show Gist options
  • Save gauravtiwari/8e3a8f021b913276548cf8004523070f to your computer and use it in GitHub Desktop.
Save gauravtiwari/8e3a8f021b913276548cf8004523070f to your computer and use it in GitHub Desktop.
Use linkedin client side sdk for oauth2
/* global window IN Routes */
import $ from 'jquery';
export default class Linkedin {
constructor() {
$.getScript(window.LINKEDIN_JS_SDK_URL, (data, textStatus) => {
if (textStatus === 'success') {
IN.init({
api_key: window.LINKEDIN_CLIENT_ID,
scope: 'r_basicprofile r_emailaddress',
lang: 'en_US',
credentials_cookie: true,
});
}
});
}
authenticate() {
return new Promise((resolve, reject) => {
IN.User.authorize(() => {
const auth = IN.ENV.auth;
const expirationTime = new Date();
expirationTime.setSeconds(expirationTime.getSeconds() + 1800);
resolve({
access_token: auth.oauth_token,
uid: auth.member_id,
expires_at: expirationTime,
});
}, () => { reject('Can not login. Please try again!'); });
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment