passport-js
Passport.jsを使って、GoogleやGitHubアカウント、メールアドレスなどを用いたログイン機能や、OAuth認証、セッション認証などをExpressアプリケーションに簡単に追加し、セキュアな認証機能を実装するSkill。
📜 元の英語説明(参考)
Add authentication to Express with Passport.js. Use when implementing login with Google/GitHub/email, OAuth, session auth, or social login.
🇯🇵 日本人クリエイター向け解説
Passport.jsを使って、GoogleやGitHubアカウント、メールアドレスなどを用いたログイン機能や、OAuth認証、セッション認証などをExpressアプリケーションに簡単に追加し、セキュアな認証機能を実装するSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o passport-js.zip https://jpskill.com/download/15237.zip && unzip -o passport-js.zip && rm passport-js.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/15237.zip -OutFile "$d\passport-js.zip"; Expand-Archive "$d\passport-js.zip" -DestinationPath $d -Force; ri "$d\passport-js.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
passport-js.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
passport-jsフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
Passport.js
概要
Passport.js は、Express で最も人気のある認証ミドルウェアであり、500 以上のストラテジー(Google、GitHub、Facebook、SAML、LDAP、local)に対応しています。デフォルトではセッションベースですが、JWT とも連携できます。
手順
ステップ 1: Local Strategy
import passport from 'passport'
import { Strategy as LocalStrategy } from 'passport-local'
import bcrypt from 'bcrypt'
passport.use(new LocalStrategy(
{ usernameField: 'email' },
async (email, password, done) => {
const user = await db.users.findByEmail(email)
if (!user) return done(null, false, { message: 'No account' })
if (!await bcrypt.compare(password, user.passwordHash)) return done(null, false)
return done(null, user)
}
))
passport.serializeUser((user: any, done) => done(null, user.id))
passport.deserializeUser(async (id, done) => done(null, await db.users.findById(id)))
ステップ 2: Google OAuth
import { Strategy as GoogleStrategy } from 'passport-google-oauth20'
passport.use(new GoogleStrategy({
clientID: process.env.GOOGLE_CLIENT_ID!,
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
callbackURL: '/auth/google/callback',
}, async (accessToken, refreshToken, profile, done) => {
let user = await db.users.findByOAuthId('google', profile.id)
if (!user) user = await db.users.create({
email: profile.emails![0].value,
name: profile.displayName,
oauthProvider: 'google', oauthId: profile.id,
})
return done(null, user)
}))
ステップ 3: ルート
app.post('/login', passport.authenticate('local', {
successRedirect: '/dashboard', failureRedirect: '/login',
}))
app.get('/auth/google', passport.authenticate('google', { scope: ['profile', 'email'] }))
app.get('/auth/google/callback', passport.authenticate('google', {
successRedirect: '/dashboard', failureRedirect: '/login',
}))
ガイドライン
- パスワードは bcrypt でハッシュ化してください(コスト 12 以上)。プレーンテキストで保存しないでください。
- 本番環境では、Redis ストアで express-session を使用してください。
- セッションベースの認証で CSRF 保護を実装してください。
- アカウントをリンクしてください。ユーザーが複数の OAuth プロバイダーを 1 つのアカウントに接続できるようにします。
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Passport.js
Overview
Passport.js is the most popular auth middleware for Express with 500+ strategies (Google, GitHub, Facebook, SAML, LDAP, local). Session-based by default, works with JWTs too.
Instructions
Step 1: Local Strategy
import passport from 'passport'
import { Strategy as LocalStrategy } from 'passport-local'
import bcrypt from 'bcrypt'
passport.use(new LocalStrategy(
{ usernameField: 'email' },
async (email, password, done) => {
const user = await db.users.findByEmail(email)
if (!user) return done(null, false, { message: 'No account' })
if (!await bcrypt.compare(password, user.passwordHash)) return done(null, false)
return done(null, user)
}
))
passport.serializeUser((user: any, done) => done(null, user.id))
passport.deserializeUser(async (id, done) => done(null, await db.users.findById(id)))
Step 2: Google OAuth
import { Strategy as GoogleStrategy } from 'passport-google-oauth20'
passport.use(new GoogleStrategy({
clientID: process.env.GOOGLE_CLIENT_ID!,
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
callbackURL: '/auth/google/callback',
}, async (accessToken, refreshToken, profile, done) => {
let user = await db.users.findByOAuthId('google', profile.id)
if (!user) user = await db.users.create({
email: profile.emails![0].value,
name: profile.displayName,
oauthProvider: 'google', oauthId: profile.id,
})
return done(null, user)
}))
Step 3: Routes
app.post('/login', passport.authenticate('local', {
successRedirect: '/dashboard', failureRedirect: '/login',
}))
app.get('/auth/google', passport.authenticate('google', { scope: ['profile', 'email'] }))
app.get('/auth/google/callback', passport.authenticate('google', {
successRedirect: '/dashboard', failureRedirect: '/login',
}))
Guidelines
- Hash passwords with bcrypt (cost 12+). Never store plaintext.
- Use express-session with Redis store in production.
- Implement CSRF protection with session-based auth.
- Link accounts: let users connect multiple OAuth providers to one account.