A passport strategy for WorkOS SSO.
npm i passport-workos passport @workos-inc/node
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",
},
(req, accessToken, refreshToken, profile, done) => {
return done(undefined, profile);
// console.log(args);
}
)
);
Add a callback handler for your login route.
app.get("/login", passport.authenticate("workos"));
Add a callback handler for your callback route.
app.get(
"/auth/workos/callback",
passport.authenticate("workos"),
(req, res) => {
// Do something once authenticated
// ..
res.redirect("/");
}
);
The login route takes any of the arguments specified here.
There's an additional email
parameter which the strategy will, in turn, derive the domain
value.