Set up OAuth 2.0 with multiple providers
✓Works with OpenClaudeYou are a backend authentication engineer. The user wants to set up OAuth 2.0 with multiple providers (Google, GitHub, Microsoft) in a Node.js application.
What to check first
- Run
npm list passport passport-google-oauth20 passport-github2 passport-microsoftto verify OAuth strategy packages are installed - Confirm you have
.envfile withCLIENT_ID,CLIENT_SECRET, andCALLBACK_URLfor each provider - Check that your Express server has
express-sessionandpassportmiddleware initialized before route handlers
Steps
- Install required packages:
npm install passport passport-google-oauth20 passport-github2 passport-microsoft express-session dotenv - Create a
config/passport.jsfile to configure each OAuth strategy withnew GoogleStrategy(),new GitHubStrategy(), andnew WindowsLiveStrategy() - Set
passport.serializeUser()andpassport.deserializeUser()to handle session persistence with user ID - In your main Express file, initialize
passport.initialize()andpassport.session()middleware afterexpress-session - Create
/auth/:providerroutes that callpassport.authenticate('google'),passport.authenticate('github'), etc. - Create
/auth/:provider/callbackroutes withpassport.authenticate()as middleware, then redirect to dashboard on success - Add
/logoutroute that callsreq.logout((err) => {...})and destroys the session - Create a user model/table to store
oauth_id,provider,email,display_namefrom the OAuth profile
Code
// config/passport.js
const passport = require('passport');
const GoogleStrategy = require('passport-google-oauth20').Strategy;
const GitHubStrategy = require('passport-github2').Strategy;
const WindowsLiveStrategy = require('passport-microsoft').Strategy;
const User = require('../models/User');
passport.serializeUser((user, done) => {
done(null, user.id);
});
passport.deserializeUser(async (id, done) => {
try {
const user = await User.findById(id);
done(null, user);
} catch (err) {
done(err, null);
}
});
passport.use(new GoogleStrategy({
clientID: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
callbackURL: process.env.GOOGLE_CALLBACK_URL
}, async (accessToken, refreshToken, profile, done) => {
try {
let user = await User.findOne({ oauth_id: profile.id, provider: 'google' });
if (!user) {
user = await User.create({
oauth_id: profile.id,
provider: 'google',
email: profile.emails[0].value,
display_name: profile.display
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Authentication Skills
Other Claude Code skills in the same category — free to download.
JWT Auth
Implement JWT authentication from scratch
NextAuth Setup
Configure NextAuth.js/Auth.js
Passport Setup
Set up Passport.js with strategies
Magic Link Auth
Implement passwordless magic link auth
Two Factor Auth
Add 2FA/MFA to authentication flow
Session Management
Implement secure session management
API Key Auth
Create API key authentication system
SSO Setup
Set up Single Sign-On (SAML/OIDC)
Want a Authentication skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.