Skip to content

Sign in with Slack

For: an app developer whose users work in Slack workspaces.

What it does: social.slack adds a “Continue with Slack” button on the OpenID Connect endpoints of Slack. Core finds or makes the user by the workspace id and the user id.

Before you rely on this preset, sign in once with a real account.

  1. Add https://<your api host>/auth/social/slack/callback to the redirect URLs of the Slack app.
  2. Copy the client id and the client secret to your secret store.
  3. Set social.slack with clientId and clientSecret.
  4. Link to /auth/social/slack/start?next=/home from the sign-in page.
The Slack preset in the config
import { createAuth, type MailPort, type StorageAdapter } from "@authtempo/core";
export function createSlackAuth(deps: { storage: StorageAdapter; mail: MailPort; secret: string }) {
return createAuth({
baseURL: "https://api.example.com",
appURL: "https://app.example.com",
trustedOrigins: ["https://app.example.com"],
secret: deps.secret,
storage: deps.storage,
mail: deps.mail,
social: {
// Read the secret from your secret store. The placeholders only build the config.
slack: { clientId: "1234567890.1234567890", clientSecret: "slack-client-secret" },
},
});
}
The start as a test
import { describe, expect, it } from "vitest";
import { call, harness } from "../support/harness.ts";
import { createSlackAuth } from "./slack.ts";
describe("sign in with Slack", () => {
it("sends the person to the provider with the scope and a PKCE challenge", async () => {
const auth = createSlackAuth(harness());
const res = await call(auth, "GET", "/auth/social/slack/start?next=/home");
expect(res.status).toBe(302);
const to = new URL(res.headers.get("location") ?? "");
expect(to.origin + to.pathname).toBe("https://slack.com/openid/connect/authorize");
expect(to.searchParams.get("scope")).toBe("openid profile email");
expect(to.searchParams.get("redirect_uri")).toBe(
"https://api.example.com/auth/social/slack/callback",
);
expect(to.searchParams.get("code_challenge_method")).toBe("S256");
});
});
  • The scope is openid profile email. Core reads the profile from openid.connect.userInfo.
  • The subject is <team_id>:<user_id>, such as T123:U456. Slack says a user id is unique only in its workspace. A user id alone from a second workspace could sign in as another person.
  • Slack answers an error with status 200 and ok: false. The token answer and the profile answer must each hold ok: true, else oauth_failed.
  • A profile with no team id or no user id answers oauth_failed.
  • An address counts as verified only with email_verified: true. An unverified address links no user that exists.
  • Under Slack Enterprise Grid, one person can be in two workspaces. Each workspace gives a new subject, so that person gets two accounts.
  • Better Auth keeps the user id alone as the subject of a Slack account. A Better Auth account row of the provider slack does not match the core subject by itself.
  • Before you go live, confirm with a real sign-in that the profile holds the team id. Core’s tests use recorded answers.
  • oauth_failed: the token call or the profile call answered ok: false, or the profile has no team id. Check the client id, the secret, and the scopes.
  • oauth_denied: the person refused at Slack.
  • email_taken_unverified: another user holds the address, and Slack did not verify it.
  • invalid_token: the state is spent or old, or the callback came to another browser. Start again.
  • sign_up_closed: the sign-up rule refused a new user.