4

I am trying to get LinkedIn Access Token after login. Login is working fine with JavaScript SDK and I'm able to receive "oauth_token" and member_id. I need access_token to verify the email address (if it is not forged on the way).

Below is my script:

<script>
function LoginWithLinkedIn() {
        IN.User.authorize(afterAuthorization); 
    }
    function afterAuthorization(response){
        debugger
        if(IN.User.isAuthorized()==true){
            getProfileData();
        }
    }
    function onSuccess(data) {
        console.log(data);
    }
    function onError(error) {
        console.log(error);
    }
    function getProfileData(r) {
        IN.API.Profile("me")
         .fields("id,firstName,lastName,email-address,picture-urls::(original),public-profile-url,location:(name)")
         .result(onSuccess)
         .error(onError);
    }
</script>

I need help getting the access_token after successful authorization. Any help is highly appreciated!

Thanks!

Sunny Sharma
  • 4,688
  • 5
  • 35
  • 73
  • get access token from your account of your linkedIn ID see [this](http://www.oauthforaspnet.com/providers/linkedin/) – M.Y.Mnu Aug 31 '16 at 11:45
  • But I want to perform by using Java Script and C#. Because this redirects me to linkedin and then perform login and after then again redirect to my application. –  Aug 31 '16 at 11:52
  • @Panky26 Do you have other Idea –  Aug 31 '16 at 11:53
  • have a look on this [link](http://www.aspdotnet-suresh.com/2013/05/integrate-linkedin-login-button-to.html) – M.Y.Mnu Aug 31 '16 at 12:00
  • I have done already this process now I want to again verify after login on server side –  Aug 31 '16 at 12:11
  • both you have, now you have to create logic – M.Y.Mnu Aug 31 '16 at 12:22

1 Answers1

2

Hope following code will work

function LinkedInLogin() {
    IN.User.authorize(getProfileData);
}
function onSuccess(data) {
    jQuery('#hdnAccessToken').val(IN.ENV.auth.oauth_token);
    try {
        jQuery('#hdnSocialLoginType').val('in');
        jQuery('#HiddenFieldUserId').val(data.values[0].id);
        jQuery('#HiddenFieldEmail').val(data.values[0].emailAddress);
        jQuery('#HiddenFieldFirstName').val(data.values[0].firstName);
        jQuery('#HiddenFieldLastName').val(data.values[0].lastName);
        jQuery('#HiddenFieldType').val('linkedin');
        jQuery('#BtnLoginSocial').click();
    }
    catch (err) {
        alert(jQuery('#HiddenErrorMessage').val());
    }
    //console.log(data);
}
function onError(error) {
    console.log(error);
}
function getProfileData() {
    if (IN.User.isAuthorized() == true) {
        IN.API.Profile("me").fields("id,firstName,lastName,email-address").result(onSuccess).error(onError);
    }
}
Sourabh Somani
  • 2,138
  • 1
  • 13
  • 27