Communitygithub.com

YepAPI/skills

Google/GitHub/Discord OAuthフロー、PKCE、トークンリフレッシュ、セッション管理を提供します。

skills とは?

このスキルは、Google、GitHub、DiscordのOAuth認証フローを安全に実装するためのベストプラクティス集です。公開クライアント(SPAやモバイルアプリ)向けにはPKCEを用いたAuthorization Codeフローを推奨し、Implicitフローを禁止しています。StateパラメータによるCSRF対策、サーバーサイドでのトークン交換、リフレッシュトークンの管理、セッション管理のパターンを網羅しており、複数のOAuthプロバイダを同じアカウントに統合する機能もサポートします。主にWebアプリケーション開発者向けで、Next.jsなどのフレームワークでOAuthコールバックを処理する際のコード例も含まれています。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/YepAPI/skills/tree/HEAD/skills/oauth-providers

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

OAuthプロバイダー

ルール

  • 公開クライアント(SPA、モバイル)向けには、Implicitフローではなく、PKCEを用いたAuthorization Codeフローを使用すること
  • ウェブアプリではサーバーサイドでコード交換を行うこと(クライアントシークレットはサーバーから外部に出してはならない)
  • Stateパラメータ: ランダムな state を生成し、セッション/クッキーに保存し、コールバックで検証すること(CSRF対策)
  • Google OAuth: スコープ openid email profile、ユーザー情報は id_token を使用
  • GitHub OAuth: スコープ read:user user:email、トークン交換エンドポイント https://github.com/login/oauth/access_token
  • Discord OAuth: スコープ identify email、トークンエンドポイント https://discord.com/api/oauth2/token
  • トークンリフレッシュ: refresh_token をサーバーサイドに保存し、access_token の期限切れ前にリフレッシュすること
  • セッション管理: OAuthコールバック成功時にアプリセッションを作成し、OAuthトークンをクッキーに保存しないこと
  • アカウント連携: accounts テーブルを介して、ユーザーが複数のプロバイダを1つのアカウントに接続できるようにする

パターン

// OAuthコールバックハンドラ
export async function GET(req: Request) {
  const { searchParams } = new URL(req.url);
  const code = searchParams.get("code");
  const state = searchParams.get("state");

  // stateが保存された値と一致するか検証
  if (state !== cookies().get("oauth_state")?.value) {
    return new Response("Invalid state", { status: 400 });
  }

  // コードをトークンと交換
  const tokens = await exchangeCodeForTokens(code);
  const userInfo = await fetchUserInfo(tokens.access_token);

  // アカウントを作成またはリンク、セッションを作成
  const user = await upsertUser(userInfo);
  await createSession(user.id);

  return redirect("/dashboard");
}

避けるべきこと

  • フロントエンドコードにクライアントシークレットを保存すること(常にサーバーサイドでトークン交換を行うこと)
  • state パラメータを省略すること(CSRF攻撃は現実に存在する)
  • 生のOAuthトークンをクッキーに保存すること(サーバーサイドセッションを使用すること)
  • プロバイダ連携時に「そのメールアドレスを持つユーザーが既に存在する」ケースの処理を忘れること

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

YepAPI/skills

WCAG 2.1 AA — semantic HTML, keyboard navigation, screen readers.

YepAPI/skills

Experiment setup, variant splitting, statistical significance, and feature flag integration.

YepAPI/skills

CRUD generators, data tables, user management, role-based access, and bulk operations.

YepAPI/skills

Monitor what ChatGPT and Gemini say about your brand using YepAPI.

YepAPI/skills

Queue workers with BullMQ/Inngest/Trigger.dev, job retries, dead letter queues, concurrency.

YepAPI/skills

Commander.js, interactive prompts with Clack, spinners, colors, config files, exit codes, and npm publishing.

YepAPI/skills

cmdk integration, Cmd+K trigger, fuzzy search, grouped actions, keyboard navigation, and dynamic action registration.

YepAPI/skills

Content planning with trend and sentiment data from YepAPI.

YepAPI/skills

Content calendar, keyword-driven planning, and content briefs.

YepAPI/skills

Theme switching with CSS variables, system preference detection, next-themes, and persistence.

YepAPI/skills

Threaded comments, @mentions, reactions, moderation queue, optimistic UI, and cursor pagination.

YepAPI/skills

Competitive analysis between domains using YepAPI.

YepAPI/skills

Layout grids, KPI cards, data tables with sorting/filtering, sidebar navigation, and responsive breakpoints.

YepAPI/skills

Data encryption — TLS everywhere, AES-256-GCM for PII, bcrypt passwords, encrypted backups.

YepAPI/skills

Chart patterns with Recharts/Nivo/D3, responsive containers, color scales, and accessibility.

YepAPI/skills

Drizzle schema definition, push vs migrate, type-safe queries, relations, transactions, and prepared statements.

YepAPI/skills

Upload handling, resize/compress, CDN delivery, blur placeholders, and next/image patterns.

YepAPI/skills

Local business and Google Maps research using YepAPI.

YepAPI/skills

Cursor-based pagination, IntersectionObserver, virtualized lists with @tanstack/react-virtual, and scroll position restoration.

YepAPI/skills

Chat UI components, streaming responses with AI SDK, context window management, and RAG patterns.

関連スキル