function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Brahim HadiBrahim Hadi 

Linkedin Auth Provider error

Hi Experts,

I followed all the instructions on how to create a LinkedIn authentication with OAuth 2.0 (https://developer.linkedin.com/docs/oauth2), but still I couldn't get it working.
I am getting this error when I try to login to my user community via LinkedIn login: 
"We can’t log you in because of the following error. For more information, contact your Salesforce administrator.
No_Oauth_State: State was not valid
"

Test-Only Initialization URL works fine.

Do you have any idea what could be wrong in my configuration?

Best regards,
Huda

Here are my settings:
User-added image

User-added image
 
Best Answer chosen by Brahim Hadi
Brahim HadiBrahim Hadi
To be honest I am not a developer. According to Eclipse there is no syntax error in this class. So, it must be a logical error.

 

All Answers

Andy BoettcherAndy Boettcher
Are you getting the error from the LinkedIn site or Salesforce itself?
Brahim HadiBrahim Hadi
I am not getting the  "State was not valid" error anymore. I think this error was because of my session which had expired.
Now I am getting a new error which says:
"We can’t log you in because of the following error.
REGISTRATION_HANDLER_ERROR: List has no rows for assignment to SObject
"

I am getting this error from the Salesforce itself.
I am using this Registration Handler class which I haven't modify anything to it: https://github.com/salesforceidentity/social-signon-reghandler/blob/master/SocialRegHandler.cls

Could you please help to check what is the issue here?

Thank you in advance,
Huda

 
Andy BoettcherAndy Boettcher
What line of the class is that error happening at?
Brahim HadiBrahim Hadi
To be honest I am not a developer. According to Eclipse there is no syntax error in this class. So, it must be a logical error.

 
This was selected as the best answer
Brahim HadiBrahim Hadi
Hi Andy,

The issue is now solved and everything is working as expected :-).
I modified the Registration Handler class so that it will just check if the user exists in salesforce or not:
- If the LinkedIn user is found in the Salesforce DB he can login to the user community.
- If the LinkedIn user is not found in the Salesforce DB he cannot login the user community and a proper message will be displayed.
Here is the whole class:
global class SimpleSocialRegHandlerV2 implements Auth.RegistrationHandler{
    class RegHandlerException extends Exception {}
        global User createUser(Id portalId, Auth.UserData data){       
        try{
        User u = [SELECT ID FROM User Where Username = :data.email];
        return u;

        } catch (Exception e){
        throw new RegHandlerException('Cannot find this user. For help, contact your administrator.');
        }
}
}
Now I need to write a unit test for it. So, could you please help me?

Best regards,
Huda

 
Rick UptonRick Upton
Hi Huda,

Thanks for posting your code, it works great for me for Google Social Sign On. Would you be able to post the test classes you wrote for this code?

Best regards,

Rick