Sign in with Slack

Mark McEahern
Jun 10, 2016 · 2 min read

At Manifestly, we’re investing in the Slack platform. In this article, I’ll show you exactly how we enabled sign in with Slack.

First, we added the button to our login page:

# apps/views/devise/shared/_links.html.erb
<%= sign_in_with_slack_button %>

We generated the initial html of the button using Slack’s sign in button generator. We extracted this to a helper:

# app/helpers/slack_helper.rbmodule SlackHelper
def sign_in_with_slack_button
%Q(<a href="{slack_login_url}&scope=identity.basic,,,identity.avatar&client_id=#{Chamber.slack.client_id}"><img alt="Sign in with Slack" height="40" width="172" src="" srcset=" 1x, 2x" /></a>).html_safe

The helper depends on some environment-specific settings (we use the Chamber gem) and a route:

# config/routes.rbnamespace :slack do
get 'login', to: 'sessions#create'

The route depends on a controller, where most of the magic happens. First, I’ll show you the simplicity of the create action:

def create

All of the preconditions of ensuring that user is a legitimate user are handled with before actions:

  1. Ensure the oauth_access method had no errors.
  2. Ensure the oauth_access method is ok.
  3. Ensure there is a Manifestly account corresponding to the user’s Slack team.
  4. Ensure the Manifestly account still has a valid token.
  5. Find the user by email in the Manifestly account.

Here’s the controller and its tests, which I’ve shared in a public gist:

We use the slack-ruby-client gem (among others) provided by Daniel Doubrovkine. He’s written a number of useful Slack gems.

The other dependencies are internal and have to do with how we manage accounts and users in Manifestly:

  1. An Account has many Users through a Membership model.
  2. The User model is the authentication resource.
  3. When someone adds our Slack app, they are adding it to the Account, which has one SlackToken.

We write about checklists on Medium at Manifestly ❤ Checklists. Does your team have recurring processes? (Most teams do.) Find out why teams love Manifestly by giving our service a try!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store