How to login into Salesforce using Google credentials?

To login into Salesforce using Google credentials, use the below steps

1. Go to "https://console.developers.google.com/project".

2. Click "Create Project".


3. Enter project name and click "Create".


4. Go to "Credentials" and click "Create new Client ID".


5. Select "Web Application", remove default in "AUTHORIZED JAVASCRIPT ORIGINS" and click "Create Client ID".


6. Go to "Consent Screen" and enter the Product Name.


7. Go to your Salesforce.com Setup --> Administer --> Security Controls --> Auth. Providers and click "New".


8. Enter the details as below.


In order to get the Consumer Key and Consumer Secret, get Client Id and Client Secret from your Google Project.


9. Copy the Callback URL from Auth. Provider and paste it in Redirec URI.




10. An apex class would have been created. Go to Setup --> Build --> Develop --> Apex Classes and edit the class as mentioned below.

global class AutocreatedRegHandler1406191530150 implements Auth.RegistrationHandler {
    global User createUser(Id portalId, Auth.UserData data) {
        User u = [SELECT Id FROM User WHERE Email =: data.email];
        return u;
    }
    
    global void updateUser(Id userId, Id portalId, Auth.UserData data) {
    }
}

here you can make use of data.FirstName, data.LastName, data.FullName, openid(Google Profile Id) also.

11. Copy the Test-Only authrorization url and paste it in your brower and press enter.




12. Provide Single Sign-On Initialization URL to your organization user to login into Salesforce using Google credentials.

Note: Sometimes, it will get some time to get synchronized. If you get any error in the URL, kindly try after sometime.

Cheers!!!

4 comments:

  1. Hi Sir

    I configure everything as per this following steps but i receive a Error response as when i copy the test url then it moves to the url 'https://ap1.salesforce.com/_nc_external/identity/sso/ui/AuthorizationError?ErrorCode=No_Openid_Response&ErrorDescription=Bad+response' and throw the response as Error

    There was a problem with your authentication attempt. Please try again. If you continue to encounter problems, contact your administrator.

    ReplyDelete
    Replies
    1. I am getting the same error but different content in the URL

      https://cs9.salesforce.com/_nc_external/identity/sso/ui/AuthorizationError?ErrorCode=CSRF&ErrorDescription=No+CSRF+cookie#


      Page displays: "Error There was a problem with your authentication attempt. Please try again. If you continue to encounter problems, contact your administrator."

      Delete
    2. Hello
      Did you solve this ? I am having the same issue..
      thank you for your help :)

      Christophe

      Delete
    3. Hello
      Did you solve this ? I am having the same issue..
      thank you for your help :)

      Christophe

      Delete