• Nguyễn Văn Tiến
  • NEWBIE
  • 10 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 2
    Replies
Hi everyone, 

I have asked this question before but it seems that the post has gotten to the forgotten zone and no one has yet an answer so I just repost the question.

When we use the AuthProviders for Single Sign-on, there's a Registration Handler. For the most part of the handler, I did as Salesforce told. But now I want to do more, I want to get more information of basic profile from the associated websites. For that I need to have the access token for REST API call. But when I use Auth.AuthToken.getAccessToken('0SO7xxx', 'LinkedIn') in my Handler it return a null token.

Can anybody tell me why does the method getAccessToken return null? Or show me another way to get the access token?
Hi everyone,

When we use the AuthProviders for Single Sign-on, there's a Registration Handler. For the most part of the handler, I did as Salesforce told. But now I want to do more, I want to get more information of basic profile from the associated websites. For that I need to have the access token for REST API call. But when I use Auth.AuthToken.getAccessToken('0SO7xxx', 'LinkedIn') in my Handler it return a null token.

Can anybody tell me why does the method getAccessToken return null? Or show me another way to get the access token?

Hi everyone,

Right now, I have connected my salesforce user to LinkedIn using OAuth. But now I want to get the basic information from LinkedIn user using Apex.
Linked In has provided 2 pages for this but to be honest, I'm clueless about OAuth or Rest API.

I have try to authenticate to OAuth using the code below but it always said "No_Oauth_State: State was not valid linkedin". Can anyone help me to fix this bug and get the profile data using REST API after that:

public class LinkedInAuth {
    
    
    public string theCode {get;set;}
    public string theTokenResponse {get;set;}
    
    /*******************************************
    *
    *   Get Authorization Code
    *
    *******************************************/
    
    public pagereference auth_Step_1(){
        
        String auth_url = 'https://www.linkedin.com/oauth/v2/authorization';
        String params =  
            '?response_type=code' +
            '&client_id=*************' +
            '&redirect_uri=https://login.salesforce.com/services/authcallback/00D7F000000opivUAA/DemoSync' + 
            //                            '&prompt=consent' + 
            '&scope=' + encodingUtil.URLEncode('r_basicprofile w_share','UTF-8') +
            '&state=DCEeFWf45A53sdfKef424';
        pageReference pr = New PageReference(auth_url + params);            
        return pr;
    }
    
    /*******************************************
    *
    *   Get Access Token
    *
    *******************************************/
    
    
    public pagereference auth_Step_2(){
        
        if(apexPages.currentPage().getParameters().get('state') != 'DCEeFWf45A53sdfKef424')
            return null;
        
        theCode = apexPages.currentPage().getParameters().get('code');
        
        HttpRequest req = new HttpRequest();
        Http http = new Http();
        
        String auth_url = 'https://www.linkedin.com/oauth/v2/accessToken';
        String params =  
            '?code=' + apexPages.currentPage().getParameters().get('code') +
            '&grant_type=authorization_code' + 
            '&client_id=************' +
            '&client_secret=***************' + 
            '&redirect_uri=https://login.salesforce.com/services/authcallback/00D7F000000opivUAA/DemoSync';
        
        req.setMethod('POST');
        req.setEndpoint(auth_url + params);
        req.setHeader('Content-Type','application/x-www-form-urlencoded');
        req.setHeader('Content-Length',string.valueOf(req.getBody().length()));
        
        HTTPResponse resp = http.send(req);
        
        
        theTokenResponse = resp.getBody();
        
        return null;
        
    }
}
Hi everyone!

I just started with Salesforce but now I'm facing a problems that I have yet to find a solution for. Here 's the problem:

Now, when a user log in with an external website, say google or outlook (or even facebook, twitter, linkedin if possible), his profile data (name, avatar, contact, ...) in salesforce will be that in the external website, the user no longer need to input his information to salesforce profile.

Then, when the user changes his profile data in the external website, his salesforce profile data will automatically sync with his salesforce profile, and the other way around.
 
Hi everyone,

When we use the AuthProviders for Single Sign-on, there's a Registration Handler. For the most part of the handler, I did as Salesforce told. But now I want to do more, I want to get more information of basic profile from the associated websites. For that I need to have the access token for REST API call. But when I use Auth.AuthToken.getAccessToken('0SO7xxx', 'LinkedIn') in my Handler it return a null token.

Can anybody tell me why does the method getAccessToken return null? Or show me another way to get the access token?

Hi everyone,

Right now, I have connected my salesforce user to LinkedIn using OAuth. But now I want to get the basic information from LinkedIn user using Apex.
Linked In has provided 2 pages for this but to be honest, I'm clueless about OAuth or Rest API.

I have try to authenticate to OAuth using the code below but it always said "No_Oauth_State: State was not valid linkedin". Can anyone help me to fix this bug and get the profile data using REST API after that:

public class LinkedInAuth {
    
    
    public string theCode {get;set;}
    public string theTokenResponse {get;set;}
    
    /*******************************************
    *
    *   Get Authorization Code
    *
    *******************************************/
    
    public pagereference auth_Step_1(){
        
        String auth_url = 'https://www.linkedin.com/oauth/v2/authorization';
        String params =  
            '?response_type=code' +
            '&client_id=*************' +
            '&redirect_uri=https://login.salesforce.com/services/authcallback/00D7F000000opivUAA/DemoSync' + 
            //                            '&prompt=consent' + 
            '&scope=' + encodingUtil.URLEncode('r_basicprofile w_share','UTF-8') +
            '&state=DCEeFWf45A53sdfKef424';
        pageReference pr = New PageReference(auth_url + params);            
        return pr;
    }
    
    /*******************************************
    *
    *   Get Access Token
    *
    *******************************************/
    
    
    public pagereference auth_Step_2(){
        
        if(apexPages.currentPage().getParameters().get('state') != 'DCEeFWf45A53sdfKef424')
            return null;
        
        theCode = apexPages.currentPage().getParameters().get('code');
        
        HttpRequest req = new HttpRequest();
        Http http = new Http();
        
        String auth_url = 'https://www.linkedin.com/oauth/v2/accessToken';
        String params =  
            '?code=' + apexPages.currentPage().getParameters().get('code') +
            '&grant_type=authorization_code' + 
            '&client_id=************' +
            '&client_secret=***************' + 
            '&redirect_uri=https://login.salesforce.com/services/authcallback/00D7F000000opivUAA/DemoSync';
        
        req.setMethod('POST');
        req.setEndpoint(auth_url + params);
        req.setHeader('Content-Type','application/x-www-form-urlencoded');
        req.setHeader('Content-Length',string.valueOf(req.getBody().length()));
        
        HTTPResponse resp = http.send(req);
        
        
        theTokenResponse = resp.getBody();
        
        return null;
        
    }
}