Slack and Salesforce Integration: Authentication

This is another installment in my ongoing Slack and Salesforce integration series.

In part 2 (Slash Commands) and part 3 (Bots), I used an “integration user” to access Salesforce on behalf of Slack users. In other words, all Slack users connected to Salesforce using the same Salesforce user. This may be fine in some cases where everybody shares a common data set, but in most cases, you want Slack users to authenticate with Salesforce individually so that Slack requests execute in the specific context of the user, with the right set of permissions.

Slack doesn’t have built-in authentication for Salesforce, but it’s easy to implement a custom authentication process which I’ll demonstrate in this article.

Watch the video to see the custom authentication process in action:

Architecture

In part 2, I described how to create a lightweight Node.js app that acts as a message broker between Slack and Salesforce. To implement our custom authentication process, we will add some code to the Node.js app to maintain a mapping between Slack user ids and Salesforce access tokens.

Here is the high level flow:

  1. Slack passes the Slack user id with each request to the service that implements a Slash Command, and with each message to Bots.
  2. When a request comes in, we check if we already have a Salesforce access token for the provided Slack user id.
  3. If we do, we call the Salesforce REST API using that token.
  4. If we don’t, we return a link that the user can click to authenticate with Salesforce using OAuth.

    Notice that the link includes the Slack User Id that is passed along throughout the OAuth process. You could encrypt that user id for additional security.
  5. At the end of the OAuth process, we will have both the Slack user id and a Salesforce access token. We store that mapping at the server-side so that the next time the user makes a request, we can retrieve the access token and use it to make the REST call to Salesforce.
  6. If the token becomes invalid, the REST call returns a 401 (not authorized) error, and we again present the login link to the user.

Source Code

The source code is available in this GitHub repository.

Code Highlights:

  • In this example, I keep track of the Slack User Id / Salesforce access token mappings in memory (see slack-salesforce-auth.js for details). In other words, Slack users will have to re-login to Salesforce if the Node.js app is restarted. You could also persist the tokens in a database. In that case you should encrypt the tokens before storing them.
  • The current version of the application doesn’t implement a refresh token workflow. When the token expires, the user will be presented with the login link again.
  • Slack also passes the integration token with each request. You should always verify that token before you handle the request to make sure an unauthorized user that gained access to a Slack user id can’t access Salesforce information by accessing the Node.js endpoint directly. For example, here is how I check the token for the /contact Slash command:
    let CONTACT_TOKEN = process.env.SLACK_CONTACT_TOKEN;
    
    if (req.body.token != CONTACT_TOKEN) {
        return res.send("Invalid token");
    }
    

Additional Resources

Also check out the Slack/Salesforce integration in the DreamHouse sample app.

76 Responses to Slack and Salesforce Integration: Authentication

  1. nik data September 1, 2016 at 2:58 am #

    It was effective subject

    # طراحی وب سایت باید گویا و حرفه ای باشد و در نگاه اول متوجه کسب و کار مورد نظر بشویم .

    # مدیریت آسان و کامل وب سایت (مدیر به راحتی تمام اجزا سایت را بتواند مطابق با سلیقه خود تغییر دهد و نیاز به تماس با کارشناس مربوطه نباشد)

    # ظاهر گرافیکی جذاب و قابل قبول و حرفه ای داشته باشد.

    # مشتری در کمترین زمان به اطلاعاتی که در مورد کسب و کار شما نیاز دارد دسترسی پیدا کند.

    # وب سایت در دستگاه های مختلف (موبایل ، تبلت ، و ….) به درستی نمایش داده شود

    # سرعت باز شدن صفحات وب سایت زیاد باشد

    .# قابل بهینه سازی برای موتورهای جستجو است

    # کدنویسی صحیح و سبکی دارد و از cms های اوپن سورس مثل وورد پرس و جوملا استفاده نشده باشد

    # یک ووب سایت حرفه ای امنیت بالایی دارد

  2. Muhammd Adnan January 11, 2018 at 12:50 am #

    Endnote x8 crack

  3. Ayo Adekola March 12, 2018 at 12:46 pm #

    Love y’all .

    • David Scott May 18, 2019 at 9:21 am #

      Very informative article i must say. Keep writing and liteblue gov is one of the best postal services out there in our country.

  4. CIIT Noida April 19, 2018 at 3:19 am #

    Thanks for sharing this amazing post with us.

    Hadoop Training Institute in Noida

    Best Hadoop Training in Noida

  5. Shravya Ch May 7, 2018 at 11:21 am #

    Can anyone help me create new channels in slack when a record is created in salesforce?

  6. Dinesh Kumar June 11, 2018 at 8:23 am #

    This is an amazing information for Slack.This information is very helpful for us.visit
    ,mobile
    app development
    for excellent tips and techniques. We are really thankful for this post.

  7. Kingsley Nwaobi October 3, 2018 at 4:26 am #

    Thanks For the info Afribaze

  8. Kingsley Nwaobi October 3, 2018 at 4:26 am #

    https://afribaze.com.ng

  9. TargbaBenjamin February 7, 2019 at 2:53 pm #

    Very informative sir. https://legacytips.com/refer24-com-ng-review-nigerias-no-1-refer-and-earn-platform/

  10. james February 22, 2019 at 12:30 pm #

    Very informative article i must say. Keep writing and liteblue gov is one of the best postal services out there in our country.

  11. TechieShot February 22, 2019 at 11:03 pm #

    You can easily from here.download EMUS4U APP on iOS

  12. Avukat Deniz June 17, 2019 at 7:26 am #

    İzmir avukatlık görevi ile birçok kişiye yardımcı olan Deniz Hukuk Bürosu hizmetlerine çeşitli dava mecralarında da devam etmektedir bunlardan bazıları; | hasta hakları davası | boşanma sebepleri ve sonuçları | avukat danışmanlığı | ağır ceza davaları vb. gibi alanlarda sizleri hukuk karşısında en iyi şekilde temsil sağlamaktayız

  13. Cakiroglu Nakliyat June 22, 2019 at 2:57 am #

    Çakıroğlu Nakliyat, Asansörlü nakliyat | Ofis taşımacılığı | Piyano taşımacılığı | Buca evden eve nakliyat | Karşıyaka evden eve nakliyat | İzmir eşya depolama vb. hizmetleri en kaliteli ve profesyonel şekilde müşterilerine sunuyor olmaktadır.

    • Cakiroglu Nakliyat August 16, 2019 at 4:39 am #

      İzmir evden eve nakliyat firması olarak hizmet veren Çakıroğlu Nakliyat firması hizmeti ve profesyonelliği ile örnek firmalardandır. Çakıroğlu nakliyat tayin dönemlerinin gelmesiyle şehirlerarası evden eve nakliyat hizmetini de sorunsuz ve ekonomik bir biçimde sunmaktadır.

    • Adegboyega Oluwasegun June 15, 2020 at 5:28 pm #

      ns xsk

  14. genericstor July 22, 2019 at 7:05 am #

    TADAGRA 20 MG brings new variety of faith in the people who have compromised with their sex life due to ED. It is loaded with Tadalafil— a formula for hardening the penis

  15. Reliablekart August 27, 2019 at 12:43 pm #

    Vidalista 10 Mg is a first-rated generic Cialis replacement which inhibits the action of PDE5 enzymes— the catalysts which prevents the penis from getting erected. Loaded up with Tadalafil, the drug ensures early and lasting erection for the men

  16. buy generic September 13, 2019 at 7:02 am #

    TADALISTA the need of big-budgeted Tadalafil-based Cialis as it possesses the congruent content and the similar effect on the erectile dysfunction (ED) in men

  17. klinik legall January 12, 2020 at 10:39 pm #

    This is my first visit to your blog! We are a team of volunteers and new initiatives in the same niche

    Hey there, You’ve done a fantastic job. I’ll certainly digg it and personally
    recommend to my friends. I’m sure they’ll be benefited from this site.

    klinik aborsi
    1. biaya aborsi
    2. biaya kuret
    3. klinik aborsi bandung
    4. klinik aborsi jakarta
    5. klinik aborsi aman
    6. klinik aborsi jakata barat
    7. klinik aborsi raden saleh
    8. klinik aborsi legal

    klinik aborsi
    a. klinik raden saleh
    b. klinik aborsi legal
    c. klinik aborsi murah
    d. biaya aborsi
    f. biaya kuret
    g. cara menunda kehamilan
    h. biaya aborsi 2020

    klinik aborsi
    1. klinik kuret kandungan
    2. cara menggugurkan kandungan
    3. biaya kuret
    4. biaya aborsi

  18. Mahraja Express March 2, 2020 at 2:59 am #

    Very Informative Information. I have read full post thanks for share with us. Thanks so much. Regards: Maharaja Express

  19. Hồng Nguyễn March 16, 2020 at 5:03 am #

    This is a very interesting post and all the details are in this post are awesome.
    hotmail login

  20. Mavitas Prefabrik A.Ş. March 26, 2020 at 1:36 am #

    Prefabrik Fabrika

  21. Adegboyega Oluwasegun June 15, 2020 at 5:29 pm #

    match highlights

  22. Adegboyega Oluwasegun June 15, 2020 at 5:29 pm #

    https://sportingrave.com/category/videos/

  23. freelicense key August 1, 2020 at 11:27 am #

    You have done a magnificent job on this article. Your work is very good and I appreciate this issue. It’s a great pleasure reading your post. I’d really like to help appreciate it with the efforts you get with writing this post. You have some real writing talent. Today I found a great article over the internet ( Malwarebytes premium free key ) For lifetime.

  24. İzmir Avukat August 31, 2020 at 6:28 am #

    İzmir avukatlık görevi ile birçok kişiye yardımcı olan Deniz Hukuk Bürosu hizmetlerine çeşitli dava mecralarında da devam etmektedir bunlardan bazıları; | hasta hakları davası | boşanma sebepleri ve sonuçları | avukat danışmanlığı | ağır ceza davaları vb. gibi alanlarda sizleri hukuk karşısında en iyi şekilde temsil sağlamaktayız izmir avukat

  25. Evden Eve Nakliyat August 31, 2020 at 6:44 am #

    İzmir evnde Eve Nakliyat Nakliyat Hizmetleri müşteri memnuniyeti odaklı bir işletme olmaktadır… İzmir Evden Eve Nakliiyat yanısıra İzmir asansörlü nakliyat hizmeti de sunmaktadır…

  26. İztem Halı Yıkama September 2, 2020 at 3:51 am #

    Urla Koltukları yıkama ne kadar önemli olduğunun farkında olmasanız bile şimdi bunu size ispatlamayı hedefliyoruz. Her gün onlarca kişinin ziyaret ettiği normal bir evin veya işyerinin en kirli yüzeylerinden birinin kanepe ve koltuklar olduğunu görmüş olabilirsiniz. Uzun bir günün ardından işten eve geldiğimizde, önce kendimizi kanepeye atarız, oturup bir film izleriz ya da hastalandığımızda üzerine uzanırız. Ya da her gün işyerimizde aynı sandalyelere oturuyoruz, misafir olarak bir işyerine gittiğimizde o koltuklara oturuyoruz ve servis edileni tüketiyoruz. Bu aktiviteler gözümüze oldukça normal görünüyor, değil mi? Normal Urla koltuk yıkama ciddiyetini yavaş yavaş anlamaya başladığınızı tahmin ediyoruz.

  27. yuvaraj singh September 9, 2020 at 3:20 am #

    Informative article , Great work
    Leanpitch provides online training in Advanced Scrum Master during this lockdown period everyone can use it wisely.
    Advanced Scrum Master Training Online

  28. Evden Eve Nakliyat September 15, 2020 at 4:52 am #

    Yıllardan beri sorunsuz taşıma işlemi İzmir evden eve nakliyat olarak gerçekleştiriyoruz. Piyasanın en önemli nakliye şirketlerinden biri olduğumuz biliyor ve sizlere sonsuz güvence veriyoruz. Bu verdiğimiz güveni boşa çıkarmayacağımızın sözünü veriyoruz. Taşımaya karar verdiğiniz İzmir Evden Eve Nakliyat hizmeti ile eşyalarınızı düzenle paketliyor ve nakliye aracımıza yüklüyoruz. Olması gereken en kısa sürede gideceği yere sorunsuz bir şekilde teslim ediyoruz.
    Piyasanın en uygun nakliye hizmetini sağlıyoruz. Elyar Nakliyat aynı zamanda İzmir Evden Eve Nakliyat firmamız Profesyonel ve güler yüzlü ekimizle hep yanınızda olduğumuzu tekrar hatırlatıyor ve sizlere huzurlu bir şekilde eşya taşımanın garantisini veriyoruz. Birçok avantajı sağlayan nakliye şirketimizden hizmet almak için hemen internet sitemizi ziyaret edin.

  29. Evden Eve Nakliyat October 6, 2020 at 4:55 am #

    İzmir Evden Eve Nakliyat, eşyalarınızın durumuna göre küçük çaplı teçhizatla veya büyük çaplı teçhizatla yapılmaktadır. Araçlar kapalı ve dış etkilerden yalıtılmış bir şekilde hazırlanmıştır. Hava şartları ne olursa olsun eşyalarınız bu durumdan hiçbir şekilde etkilenmeyecektir. Taşınma esnasında kaçıncı katta oturduğunuz veya taşındığınız evin kaçıncı katta olduğunun da hiçbir önemi yoktur İzmir Evden Eve Nakliyat ekibi en iyi işi meydana getirmektedir. İzmir Asansörlü Nakliyat hizmeti sayesinde eşyalarınızın taşıma işlemi kolay bir şekilde gerçekleştirilmektedir.

  30. Mahraja Express October 12, 2020 at 7:19 am #

    Amazing explanation about Slack and Salesforce Integration. Thanks for share with us. Thanks so much.

    Luxury Train Tours

  31. New American Store October 17, 2020 at 1:16 pm #

    I always found very much interesting content on your posts. keep posting, thanks for sharing us and giving us your precious time.
    Cobra Kai Jacket

  32. wheeler williams November 10, 2020 at 11:46 am #

    IDM Crack Build 7 Retail + Activation Key Crack has a smart download judgment accelerator that includes smart dynamic document segmentation and multi-part secure download generation to speed up IDM key downloads.idm

  33. holland kinney November 10, 2020 at 1:36 pm #

    The Latest Version Unity Pro Crack is the advanced level of production software that provides a platform to create multiplayer games, edited in real-time, and add 3D graphics to make it more fun.downloadunitypro

  34. robles conner November 10, 2020 at 1:47 pm #

    Avid Pro Tools 2020 Crack is an amazing production system app that allows users to record audio. It is a perfect tool for musicians, composers, audio enthusiasts, singers, and producers, helping them to edit, mix, write, and record music.avidprotools

  35. wagner peterson November 10, 2020 at 1:55 pm #

    SketchUp Pro Crack is a versatile 3D computer modeling architectural drawing suit that showcases excellence in interior and exterior design illustration.sketchuppro

  36. higgins chen November 10, 2020 at 2:04 pm #

    VSDC Video Editor Full Crack Download is the most powerful and popular multimedia software to create and edit all kinds of videos.vsdcvideoeditor

  37. oliver stanley November 10, 2020 at 2:27 pm #

    Tally ERP 9 Crack is a smart and first-rate program. Users have chosen it for the business management of over one million people in more than 140 countries.tallyerp

  38. lancaster raymond November 10, 2020 at 2:39 pm #

    FoneLab Aiseesoft 10.2.22 Crack is the most well-known data recovery programming for iOS contraptions.aiseesoftfonelab

  39. perry albert November 10, 2020 at 2:47 pm #

    AnyTrans 8.8.0 Crack is a proficient and hearty iOS Content Manager. Additionally, it furnishes you with both the opportunity and control of every one of your records and information, including photographs, music, messages, safari history, books, recordings, voice reminders, regardless of what the substance is on your iPhone or iCloud or even iTunes reinforcement.anytrans

  40. ayers frye November 11, 2020 at 12:11 pm #

    XSplit Broadcaster 4.0.2007.2902 Crack is the application celebrated as probably the best stage for dealing with the media content.xsplitbroadcaster

  41. smallstrick land November 11, 2020 at 12:20 pm #

    Overwatch Crack is so standard that people are in control to stream it to Xbox One, PS4, and Windows. What makes this game awesome? Considering everything, we will find the right reaction.overwatch

  42. burges osborn November 11, 2020 at 12:33 pm #

    Bitdefender Total Security Crack Innovation has been delivering award-winning information and security threats to individuals, businesses, and devices, networks, and cloud services.bitdefendertotalsecurity

  43. charles branch November 11, 2020 at 12:53 pm #

    Avid Media Composer Crack is a video and movie editing software. It enables online and offline video editing, including standard SD and high-definition HD, as well as finishing.avidmediacomposer

  44. nielsen sheppard November 11, 2020 at 1:16 pm #

    WESTWOOD Cello Untamed Free Download: CELLO UNTAMED is a solo cello library with the idea that the sample sounds like an entire performance.westwoodcellountamed

  45. lowery hewitt November 11, 2020 at 1:52 pm #

    Guitar Pro Mac Crack Free Download: Wide range of new features and improvements. Create, play, and share cards!guitarpro

  46. kidd melton November 11, 2020 at 2:18 pm #

    Wondershare Video Converter 12.0. Crack is the most trustable and acclaimed video changing over the mechanical get-together.wondersharevideoconverter

  47. alison john November 11, 2020 at 2:26 pm #

    PowerDVD Crack reads more than DVD and Blu-ray discs. For video, audio, photos, VR 360° content, and even YouTube or Vimeo, PowerDVD Crack is your funny accomplice. powerdvd

  48. yuvaraj singh November 23, 2020 at 3:10 am #

    Best blog by Leanpitch
    To crack scrum master interview : Scrum Master Interview Questions

  49. yuvaraj singh November 23, 2020 at 4:32 am #

    informative content , Great work
    To crack scrum master interview : Scrum Master Interview Questions

  50. Sam Howard December 10, 2020 at 5:34 am #

    Aurogra is an oral tablet that contains 100mg of the active ingredient sildenafil citrate. This tablet is used for the treatment of erectile dysfunction in men. Erectile dysfunction is a medical condition where men are unable to produce or maintain an erection.
    martcastle

  51. yuvaraj singh December 22, 2020 at 2:25 am #

    Thanks for sharing this informative content
    Leanpitch provides online training in Enterprise agile coaching during this lockdown period everyone can use it wisely.
    Enterprise Agile Coaching

  52. Aqeel Lashari January 3, 2021 at 11:49 pm #

    This site is best…Thanks for sharing…
    Spyhunter 5 Crack

  53. Aqeel Lashari January 3, 2021 at 11:53 pm #

    Great work dear,,,,
    Keyscape Crack

  54. yuvaraj singh January 8, 2021 at 2:07 am #

    Thanks for sharing this article
    Leanpitch provides online training in Scrum Master during this lockdown period everyone can use it wisely.
    Join Leanpitch 2 Days CSM Certification Workshop in different cities.

    CSM certification online

    CSM online

    CSM online certification

    Scrum master certification online

    CSM online training

  55. Saket Kumar February 12, 2021 at 6:14 am #

    Informative post. Great one.

  56. Aimbeatsoft tech Pvt Ltd February 24, 2021 at 2:27 am #

    Great Post, Very Informative! Do you want to know Why Designer or Developer Needs a VPN?

  57. Traffic Moto February 25, 2021 at 2:27 am #

    Thank you for valuable feedback, request you to join our email list so you can getting update via email.

    https://trafficmoto.com/digital-marketing-company-in-lucknow/

  58. Traffic Moto February 25, 2021 at 2:55 am #

    . Thanks for sharing the interesting and informative post. https://trafficmoto.com/digital-marketing-company-in-agra

  59. Mark Allen March 17, 2021 at 5:48 am #

    Visalista contains Tadalafil 20 mg as the active ingredient. Vidalista 20mg is a medicine that relaxes the smooth muscles of the walls of blood vessels, thus improving blood flow to certain parts of the body. This action makes the drug effective in treating men with erectile dysfunction. Your doctor may also prescribe Vidalista 20mg to you if you have signs and symptoms of BPH.
    Visalista 40
    Visalista 60
    Visalista 20

  60. Mark Allen March 17, 2021 at 5:48 am #

    Vilitra is an effective drug used to treat impotence and erectile dysfunction in men. Buy Super Vilitra Store properly in a cool, shady place at room temperature. The prevalence of ED increases with age. But that doesn’t mean it can’t affect young people. This disease affects men at all stages of their lives. With ED, men are unable to achieve or maintain the hard erection necessary to satisfy their sexual behavior.
    Vilitra 60
    Vilitra 20
    Super Vilitra

  61. Mark Allen March 17, 2021 at 5:49 am #

    Vigora is an approved medical use for the treatment of erectile dysfunction. If you want to buy Vigora 100mg tablets, it will be available in local drug stores and online stores.
    Genericpharmamall is an online drug store that sells 100% safe to use generic drugs and we offer the best discount and rebate on the purchase of drugs.
    Vigora 100

  62. Mark Allen March 17, 2021 at 5:49 am #

    Tadalista tablets are primarily intended for the treatment of erectile dysfunction. This drug is known as a miracle in patients with erectile dysfunction. This drug allows men to relax blood vessels and thereby increase blood flow to the penis, improving and dilating erections. This drug works faster than other drugs used for erectile dysfunction and has a much longer-lasting effect. It lasts 18 hours with a similar efficacy and safety profile. The main ingredient in this drug is tadalafil.
    Tadalista 60

Trackbacks/Pingbacks

  1. A Bot Toolkit for Creating and Deploying Bots Inside Salesforce - Developer Relations - March 13, 2017

    […] Slack and Salesforce Integration: Authentication […]

css.php