Created
November 19, 2016 11:29
-
-
Save gauravtiwari/8e3a8f021b913276548cf8004523070f to your computer and use it in GitHub Desktop.
Use linkedin client side sdk for oauth2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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