LinkedIn

Access Salesforce using Slack Credentials

 As part of Spring 22, Salesforce supports Slack as an Authentication Provider to access  Salesforce. Authentication provider helps you to implement Social Sign-On to Salesforce using different social credentials you have like Facebook, Google, or Twitter and this helps to implement an easy Single Sign-On to Salesforce.

Let us see the different steps associated with this.



1. Create a Slack workspace

If you want to implement SSO using Slack, you can use your existing business/personal slack workspace. But for test purposes, if you want to create your own workspace you can create it from here.

2. Create a Slack App

Once the workspace is created successfully(SalesforceDemo is my workspace), we need to create an App to get client id and secret. For that go to Settings & Administration->Manage Apps


Go to Build Tab at the top.


Click on Create new App


Enter an App name and choose your workspace


Scroll to App credentials section and take a note of the client ID and secret




Define Scope

Scope defines what we will be able to access in the slack workspace. As per the documentation, we need to add scopes - openid, email and profile for userinfo.



For this go to OAuth&Permissins



Under User Token Scopes add required scope:



After scope addition


3. Create an Auth. Provider with Slack

Now login to your salesforce enviornment and open Auth Provider from set up.

Click on new and select Auth provider as Slack.



Copy consumer key and secret from your App, and keep default values for Authorize, token and userinfo end point url.

Default scopes - email openid profile

Click on automatically create Registration handler.

Save the settings.



Open the handler and make the logic simpler by replacing the class with the below code:

//TODO:This autogenerated class includes the basics for a Registration
//Handler class. You will need to customize it to ensure it meets your needs and
//the data provided by the third party.

global class AutocreatedRegHandler1640843695962 implements Auth.RegistrationHandler{

    global User createUser(Id portalId, Auth.UserData data){
    
        List<User> u = [Select Id from User where Email = :data.email order by Createddate limit 1];
        if(u.size()>0){
            return u[0];
        }
        else{
        List<User> u1 = [Select Id from User where Email = 'meeraragnair@gmail.com' limit 1];
        return u1[0];
        }    
    }

    global void updateUser(Id userId, Id portalId, Auth.UserData data){
        
    }
}

4. Update Redirection URL

From the slack Auth provider settings from your org get the callback url link.


Then go to your slack App, go to Oauth & Permissions and go to session Redirect URLs. Add the call back URL value from your Salesforce org:


We have completed all basic set up now.

5. Update Mydomain setting to add Slack Login

In your Salesforce Org, go to setup->MyDomain->Edit Authentication Configuration

Update authentication service to add Slack also to the list.



6. Test Login using Slack

Now sign out, and you will see an option to login using Slack also:




Click on slack and you will be provided with an Authorization Allow page. Click on Allow:



You can see, you are getting automatically logged into your salesforce account if you are logged into your slack account already.

Useful Links:

https://help.salesforce.com/s/articleView?id=release-notes.rn_identity_slack_auth_provider.htm&type=5&release=236 








Comments

  1. Do you want to own a business of your own? or own a house of your choice?Pedro Jerome loan offer 2% rate with a flexible loan repayment to suit individual and entitle loans internationally, My loan was granted with an blick of an eye when I applied for $800,000.00 for expand my clothing business so I will advice anyone here looking for a financial help to contact pedroloanss@gmail.com or whatsapp his number on +18632310632.  I wish you goodluck.

    ReplyDelete

Post a Comment

Popular posts from this blog

Subscribing to Salesforce Platform Events using External Java Client - CometD

Salesforce Security - Restriction Rules and Scoping Rules

How to develop reusable Invocable Apex methods for Flows