🚀 DAY 5 OF LAUNCH WEEK:Introducing Webhook Events for Alert Changes.Learn more →
Socket
Book a DemoInstallSign in
Socket

passport-workos

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

passport-workos

Passport strategy for WorkOS SSO

latest
Source
npmnpm
Version
0.1.0
Version published
Weekly downloads
193
157.33%
Maintainers
1
Weekly downloads
 
Created
Source

Passport Workos

A passport strategy for WorkOS SSO.

version size coverage

Installation

npm i passport-workos passport @workos-inc/node

Setup

Import the strategy.

import { WorkOSSSOStrategy } from "passport-workos";

Instantiate it with your WorkOS credentials, callbackURL, and verify function.

passport.use(
  "workos",
  new WorkOSSSOStrategy(
    {
      clientID: process.env.WORKOS_CLIENT_ID,
      clientSecret: process.env.WORKOS_API_KEY,
      callbackURL: "http://localhost:3000/auth/workos/callback",
    },
    // Verify function
    (req, accessToken, refreshToken, profile, done) => {
      return done(undefined, profile);
    }
  )
);

Add a route for redirecting to WorkOS login.

app.get("/auth/workos/login", passport.authenticate("workos"));

Add a route for code authorization callbacks.

app.get(
  "/auth/workos/callback",
  passport.authenticate("workos"),
  (req, res) => {
    // Do something once authenticated
    // ..
    res.redirect("/");
  }
);

Consumption

Login

The login route will redirect to a WorkOS OAuth 2.0 authorization URL. When redirecting to this route, be sure to include one of the supported query parameters.

Login with email

In the likely case where the connection can't be derived by the requesting client, middleware is advised (see here).

// Client entrypoint
app.use("/auth/email/login", (req, res, next) => {
  const email = req.query.email;
  // Your custom function to get connection for given email
  const connection = await getConnectionForEmail(email);

  // Redirect to passport strategy with supported args
  res.redirect(
    url.format({
      pathname: "/auth/workos/login",
      query: { ...req.query, connection, login_hint: email },
    })
  );
});

app.use("/auth/workos/login", passport.authenticate("workos"), (req, res) => {
  /* ... */
});

Callback

This will be called by WorkOS after a successful login. Be sure to configure the redirect URI with WorkOS.

Keywords

passport

FAQs

Package last updated on 04 Nov 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts