Communityコーディング&開発github.com

clerk/clerk-chrome-extension-patterns

@clerk/chrome-extensionを使用したChrome拡張機能の認証 — ポップアップ/サイドパネルのセットアップ、ウェブアプリを介したOAuth/SAMLのsyncHost、サービスワーカーやヘッドレス拡張機能のためのcreateClerkClient、安定したCRX IDを提供します。

clerk-chrome-extension-patterns とは?

このスキルは、Clerk認証をChrome拡張機能に統合するための包括的なガイドとパターンを提供します。ポップアップやサイドパネルでの認証フロー設定、syncHostを使用したOAuthやSAML認証のためのウェブアプリ連携、サービスワーカーやヘッドレス拡張機能(例:バックグラウンドスクリプトのみの拡張機能)でのcreateClerkClientの使用方法、そして安定したCRX ID管理について詳しく説明します。特に、PlasmoフレームワークとClerkの組み合わせ、ポップアップでのサインイン、syncHostを使ったシームレスな認証、バックグラウンドサービスワーカーでのトークン管理、createClerkClientのセットアップといったユースケースに対応しています。このスキルは、開発者がChrome拡張機能に堅牢な認証を実装し、複雑なOAuthフローやSAMLフェデレーションを扱う際のベストプラクティスを提供することを目的としています。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/clerk/skills/tree/main/skills/clerk-chrome-extension-patterns

Installed? Explore more コーディング&開発 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

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

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

ドキュメント

clerk-chrome-extension-patterns は何をしますか?

@clerk/chrome-extension を使用したChrome拡張機能の認証 — ポップアップ/サイドパネルのセットアップ、ウェブアプリを介したOAuth/SAMLのためのsyncHost、サービスワーカーやヘッドレス拡張機能のためのcreateClerkClient、安定したCRX ID。トリガー: Chrome拡張機能の認証、PlasmoとClerkの連携、ポップアップサインイン、syncHost、バックグラウンドサービスワーカートークン、createClerkClient、ヘッドレス拡張機能。

概要

このスキルは、@clerk/chrome-extension を使用してChrome拡張機能に認証を追加するためのパターンを提供します。以下の主要なユースケースをカバーします:

  • ポップアップ/サイドパネル認証: ユーザーが拡張機能のポップアップやサイドパネルからサインインできるようにします。
  • syncHostによるOAuth/SAML: バックグラウンドのウェブアプリを介したOAuthやSAMLフェデレーション (syncHost) を設定します。
  • サービスワーカーとヘッドレス拡張機能: createClerkClient を使用して、サービスワーカーやUIのない拡張機能(例: バックグラウンドスクリプトのみ)でトークンを管理します。
  • 安定したCRX ID: 自動更新やOAuthリダイレクトURIの登録のための安定した拡張機能IDを設定します。

前提条件

  • @clerk/chrome-extension パッケージがインストールされていること (npm install @clerk/chrome-extension)
  • Clerkアカウントとアプリケーション (ダッシュボードから取得)
  • マニフェストV3 (推奨)

ポップアップ/サイドパネル認証

import { ClerkProvider, SignedIn, SignedOut, SignInButton, UserButton } from '@clerk/chrome-extension';

function App() {
  return (
    <ClerkProvider publishableKey={import.meta.env.VITE_CLERK_PUBLISHABLE_KEY}>
      <SignedOut>
        <SignInButton />
      </SignedOut>
      <SignedIn>
        <UserButton />
      </SignedIn>
    </ClerkProvider>
  );
}

syncHost(OAuth/SAML ウェブアプリ連携)

OAuthやSAMLプロバイダーを介した認証を使用する場合、syncHost を設定してバックグラウンドのウェブアプリとセッションを同期します。

<ClerkProvider
  publishableKey={import.meta.env.VITE_CLERK_PUBLISHABLE_KEY}
  syncHost={import.meta.env.VITE_CLERK_SYNC_HOST} // 例: https://myapp.com
>
  {/* ... */}
</ClerkProvider>

syncHost は、OAuth/SAMLプロバイダーからのリダイレクトを処理するウェブアプリのURLを指定します。

サービスワーカーとヘッドレス拡張機能

サービスワーカーやヘッドレス拡張機能(バックグラウンド専用)では、createClerkClient を使用します。

import { createClerkClient } from '@clerk/chrome-extension';

const clerkClient = createClerkClient({
  publishableKey: import.meta.env.VITE_CLERK_PUBLISHABLE_KEY,
});

// 例: トークンの取得
const token = await clerkClient.session?.getToken();

安定したCRX ID

開発中は、chrome://extensions で「デベロッパーモード」を有効にし、「パッケージ化されていない拡張機能を読み込む」を使用して、安定したIDを維持します。本番環境では、Chrome ウェブストアにアップロードすると、自動的に安定したIDが割り当てられます。

  • OAuthリダイレクトURIをClerkダッシュボードに登録する: https://[EXTENSION_ID].chromiumapp.org/__clerk_oauth_callback

Plasmoとの統合

Plasmoフレームワークを使用する場合、@clerk/chrome-extension と同様のパターンで統合できます。詳細は、PlasmoのClerkアドオン(利用可能な場合)を参照してください。

関連トピック

Individual skills in this repo

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

clerk/clerk

Clerk authentication router. Use when user asks about adding authentication, setting up Clerk, custom sign-in flows, Swift or native iOS auth, native Android auth, Next.js patterns, React patterns, Vue patterns, Nuxt patterns, Astro patterns, TanStack Start patterns, Expo patterns, React Router patterns, Chrome Extension patterns, organizations, billing, subscriptions, payments, pricing, plans, seat-based pricing, feature entitlements, syncing users, or testing. Automatically routes to the specific skill based on their task.

clerk/clerk-android

Implement Clerk authentication for native Android apps using Kotlin and Jetpack Compose with clerk-android source-guided patterns. Use for prebuilt AuthView/UserButton or custom API-driven auth flows. Do not use for Expo or React Native projects.

clerk/clerk-astro-patterns

Astro patterns with Clerk — middleware, SSR pages, island components, API routes, static vs SSR rendering. Triggers on: astro clerk, clerk astro middleware, astro protected page, clerk island component, astro API route auth, clerk astro SSR.

clerk/clerk-backend-api

Clerk Backend REST API explorer and executor. Browse tags, inspect endpoint schemas, and execute authenticated requests. Use when listing users, managing organizations, or calling any Clerk API endpoint.

clerk/clerk-billing

Clerk Billing for subscription management - render Clerk's PricingTable and in-app checkout drawer, configure subscription plans, seat-limit plans for B2B, feature entitlements with has(), and billing webhooks. Use for SaaS monetization, plan gating, checkout flows, trials, invoicing, and subscription lifecycle management.

clerk/clerk-custom-ui

Custom authentication flows and component appearance - hooks (useSignIn, useSignUp), themes, colors, fonts, CSS. Use for custom sign-in/sign-up flows, appearance styling, visual customization, branding.

clerk/clerk-expo

Implement Clerk authentication for Expo and React Native apps using @clerk/expo source-guided patterns. Use for prebuilt AuthView/UserButton or custom hook-driven auth flows. Do not use for native iOS/Swift, native Android/Kotlin, or web framework projects.

clerk/clerk-expo-patterns

Expo / React Native patterns with Clerk — SecureStore token cache, OAuth deep linking, useAuth in native, Expo Router protected routes, push notifications with user context. Triggers on: expo clerk, clerk react native, SecureStore token cache, expo router auth, OAuth deep link clerk, mobile auth clerk.

clerk/clerk-nextjs-patterns

Advanced Next.js patterns - middleware, Server Actions, caching with Clerk.

clerk/clerk-nuxt-patterns

Nuxt 3 auth patterns with @clerk/nuxt - middleware, composables, server API routes, SSR. Triggers on: Nuxt auth, useAuth composable, clerkMiddleware Nuxt, server API Clerk, Nuxt route protection.

clerk/clerk-orgs

Clerk Organizations for B2B SaaS - create multi-tenant apps with org switching, role-based access, verified domains, and enterprise SSO. Use for team workspaces, RBAC, org-based routing, member management.

clerk/clerk-react-patterns

React SPA auth patterns with @clerk/react for Vite/CRA - ClerkProvider setup, useAuth/useUser/useClerk hooks, React Router protected routes, custom sign-in flows. Triggers on: Vite Clerk setup, React Router auth, useAuth hook, protected route, custom sign-in form React.

clerk/clerk-react-router-patterns

React Router v7 patterns with Clerk — rootAuthLoader, getAuth in loaders, clerkMiddleware, protected routes, SSR user data, org switching. Triggers on: react-router auth, rootAuthLoader, getAuth loader, react-router protected route, loader authentication, SSR auth react-router.

clerk/clerk-setup

Add Clerk authentication to any project by following the official quickstart guides.

clerk/clerk-swift

Implement Clerk authentication for native Swift and iOS apps using ClerkKit and ClerkKitUI source-guided patterns. Use for prebuilt AuthView or custom native flows. Do not use for Expo or React Native projects.

clerk/clerk-tanstack-patterns

TanStack React Start auth patterns with @clerk/tanstack-react-start - createServerFn, beforeLoad guards, loaders, Vinxi server. Triggers on: TanStack auth, createServerFn clerk, beforeLoad protection, TanStack Start middleware.

clerk/clerk-testing

E2E testing for Clerk apps. Use with Playwright or Cypress for auth flow tests.

clerk/clerk-vue-patterns

Vue 3 patterns with Clerk — composables (useAuth, useUser, useClerk, useOrganization), Vue Router guards, Pinia auth store integration. Triggers on: vue clerk, useAuth vue, clerk composables, vue router clerk guard, pinia auth clerk. For Nuxt, use clerk-nuxt-patterns instead.

clerk/clerk-webhooks

Clerk webhooks for real-time events and data syncing. Verify with verifyWebhook from the framework-specific package. Handle user, session, organization, billing, and payment events. Build event-driven features like database sync, notifications, and integrations.

関連スキル