claude-skills/

Anthropic公式スキル・プラグインの日本語ディレクトリ

last sync 22h ago
スキルOfficialsecurity

🔐auth0-expo

プラグイン
auth0
ライセンス
Apache-2.0

説明

次のような場合に使用: Expo アプリに Auth0 のログイン・ログアウト・セッション管理を追加するとき。 ネイティブの iOS/Android ビルド向けに、`react-native-auth0` を Expo Config Plugin と統合します。 ユーザーが SDK に言及せず「Expo アプリにログインを追加したい」と言った場合でも使用してください。 素の React Native CLI プロジェクトには使用しないでください。

原文を表示

Use when adding Auth0 login, logout, or session management to an Expo app. Integrates react-native-auth0 with the Expo Config Plugin for native iOS/Android builds — use even if the user says "add login to my Expo app" without mentioning the SDK. Do not use for bare React Native CLI projects.

ユースケース

  • Expo アプリに Auth0 ログイン機能を追加するとき
  • Auth0 のセッション管理を実装するとき
  • iOS/Android ネイティブビルドを Auth0 認証対応させるとき

本文(日本語訳)

Auth0 Expo インテグレーション

Expo Config Plugin を使用した react-native-auth0 により、Expo(React Native)アプリケーションに認証機能を追加します。

前提条件

  • Expo SDK 53 以上(react-native-auth0 v5.x は Expo 53 以上が必要)
  • React 19 および React Native 0.78.0 以上
  • Native アプリケーションが設定済みの Auth0 アカウント
  • Auth0 がまだセットアップされていない場合は、先に auth0-quickstart スキルを使用してください
  • Expo Go との互換性はありません — カスタム開発クライアントまたは EAS Build が必要です

使用しない場合

ユースケース 推奨スキル
Bare React Native CLI プロジェクト(Expo なし) auth0-react-native
React Web SPA(Vite / CRA) auth0-react
Next.js アプリケーション auth0-nextjs
Vue.js SPA auth0-vue
Angular SPA auth0-angular
Express.js バックエンド auth0-express
ネイティブ Android(Kotlin / Java) auth0-android
バックエンド API(JWT 検証) auth0-fastify-api または auth0-express

クイックスタート手順

1. Auth0 の設定

Auth0 CLI を使った自動セットアップについては、完全なスクリプトが記載された セットアップガイド を参照してください。

手動セットアップの場合は、Auth0 ダッシュボードNative アプリケーションを設定し、Domain と Client ID を控えておいてください。

2. Expo Dev Client の確認

Agent への指示: Auth0 SDK をインストールする前に、プロジェクトに expo-dev-client がインストールされているか確認してください。プロジェクトの package.json を読み込み、dependencies または devDependencies 内に expo-dev-client が存在するか確認します。

  • expo-dev-client が見つかった場合: 手順 3 に進んでください。

  • expo-dev-client が見つからない場合: 以下のメッセージを使用して AskUserQuestion を実行してください:

    react-native-auth0 SDK にはカスタム Expo 開発クライアントが必要です — Expo Go では動作しません。このプロジェクトには expo-dev-client がインストールされていません。

    どのように進めますか?

    1. インストールするnpx expo install expo-dev-client を実行してセットアップを続行します
    2. 自分でセットアップする — このステップをスキップして Auth0 SDK のインストールに進みます」

    ユーザーがオプション 1 を選択した場合は、以下を実行してください:

    npx expo install expo-dev-client
    

    その後、手順 3 に進んでください。オプション 2 の場合は、そのまま手順 3 に進んでください。

3. SDK のインストール

npx expo install react-native-auth0

4. Expo Config Plugin の設定

app.json(または app.config.js)に react-native-auth0 プラグインを追加し、Auth0 ドメインとカスタムスキームを設定します。 また、bundleIdentifier(iOS)および package(Android)が設定されていることを確認してください:

{
  "expo": {
    "ios": { "bundleIdentifier": "com.yourcompany.yourapp" },
    "android": { "package": "com.yourcompany.yourapp" },
    "plugins": [
      ["react-native-auth0", {
        "domain": "YOUR_AUTH0_DOMAIN",
        "customScheme": "YOUR_CUSTOM_SCHEME"
      }]
    ]
  }
}

customScheme は特殊文字なしのすべて小文字にする必要があります(例: auth0sample)。 HTTPS コールバック、複数ドメイン、EAS Build、シークレット管理については セットアップガイド を参照してください。

5. コールバック URL の設定

Auth0 ダッシュボードAllowed Callback URLs および Allowed Logout URLs に以下を追加してください:

YOUR_CUSTOM_SCHEME://YOUR_AUTH0_DOMAIN/ios/YOUR_BUNDLE_ID/callback,
YOUR_CUSTOM_SCHEME://YOUR_AUTH0_DOMAIN/android/YOUR_PACKAGE/callback

すべての値は小文字で、末尾にスラッシュなしにする必要があります。 HTTPS コールバック URL(App Links / Universal Links)については セットアップガイド を参照してください。

6. Auth0Provider による認証の追加

アプリを Auth0Provider でラップし、useAuth0 フックを使用します:

Agent への指示: 新しい UI 要素を追加する前に、ログイン・ログアウト・サインイン・サインアウトボタンの既存クリックハンドラがプロジェクト内に存在しないか検索してください。既存のハンドラが見つかった場合は、そこに Auth0 のコードを組み込んでください。既存のハンドラが存在しない場合のみ、新しいボタンを作成してください。

import React from 'react';
import { Auth0Provider, useAuth0 } from 'react-native-auth0';
import { View, Button, Text, ActivityIndicator } from 'react-native';

function HomeScreen() {
  const { authorize, clearSession, user, isLoading, error } = useAuth0();

  const login = async () => {
    try {
      await authorize(
        { scope: 'openid profile email' },
        { customScheme: 'YOUR_CUSTOM_SCHEME' }
      );
    } catch (e) {
      console.error('Login error:', e);
    }
  };

  const logout = async () => {
    try {
      await clearSession({ customScheme: 'YOUR_CUSTOM_SCHEME' });
    } catch (e) {
      console.error('Logout error:', e);
    }
  };

  if (isLoading) {
    return <ActivityIndicator size="large" />;
  }

  return (
    <View>
      {user ? (
        <>
          <Text>Welcome, {user.name}!</Text>
          <Text>{user.email}</Text>
          <Button title="Log Out" onPress={logout} />
        </>
      ) : (
        <Button title="Log In" onPress={login} />
      )}
      {error && <Text>{error.message}</Text>}
    </View>
  );
}

export default function App() {
  return (
    <Auth0Provider
      domain="YOUR_AUTH0_DOMAIN"
      clientId="YOUR_AUTH0_CLIENT_ID"
    >
      <HomeScreen />
    </Auth0Provider>
  );
}

7. ビルドと検証

Agent への指示: インテグレーション完了後、以下を実行してプロジェクトがコンパイルされることを確認してください:

npx expo prebuild --clean
npx expo run:ios
# または
npx expo run:android

ビルドが失敗した場合は、エラー出力を分析してください。インテグレーション時によくあるビルドエラーには以下が含まれます:

  • 「Invariant Violation: Native module cannot be null」: 開発ビルドではなく Expo Go を使用しています — npx expo start の代わりに npx expo run:ios または npx expo run:android を実行してください
  • プラグインが適用されていない: app.json の plugins 配列に react-native-auth0 がありません — プラグインの設定を確認してください
  • Pod install の失敗(iOS): npx expo prebuild --clean を実行してネイティブプロジェクトを再生成してください
  • Manifest のマージ失敗(Android): auth0Domain プレースホルダーが競合しています — ドメインの設定は Config Plugin のみで行われていることを確認してください

修正のたびにビルドを再実行してください。ビルド修正の試行回数を記録してください。

フェイルチェック: 5〜6 回の修正を試みてもビルドが失敗し続ける場合は、AskUserQuestion を使用してユーザーに確認してください: 「複数回の修正を試みましたが、ビルドがまだ失敗しています。どのように進めますか?」

  • スキルによる反復修正を続ける
  • 手動で修正する — 残っているエラーを表示する
  • ビルド検証をスキップする — ビルドが成功しない状態で次に進む

詳細ドキュメント

  • セットアップガイド — 開発クライアントの要件、自動セットアップ、Expo Config Plugin、コールバック URL、EAS Build、シークレット管理
  • インテグレーションパターン — ログイン / ログアウト、クレデンシャル管理、生体認証、トークンリフレッシュ、Organizations、DPoP、エラーハンドリング
  • API リファレンスとテスト — 設定オプション、useAuth0 フック API、テストチェックリスト、よくある問題、セキュリティ

よくある間違い

間違い 対処法
開発ビルドではなく Expo Go を使用している react-native-auth0 はネイティブコードが必要です。npx expo run:ios / npx expo run:android を使用するか、EAS で開発ビルドを作成してください。
authorize / clearSession の呼び出しに customScheme が指定されていない authorize() および clearSession() の第 2 引数として { customScheme: 'your-scheme' } を渡してください。app.json の Plugin 設定の値と一致している必要があります。
コールバック URL の不一致 コールバック URL がすべて小文字で末尾にスラッシュがなく、Auth0 ダッシュボードの設定と完全に一致していることを確認してください: {customScheme}://{domain}/ios/{bundleId}/callback
アプリのタイプが Native に設定されていない ダッシュボードの Auth0 アプリケーションのタイプは、SPA や Regular Web ではなく Native である必要があります。
app.json に bundleIdentifier または package がない コールバック URL が機能するには、app.json に expo.ios.bundleIdentifierexpo.android.package の両方が設定されている必要があります。
アプリを Auth0Provider でラップし忘れている useAuth0() を使用するすべてのコンポーネントは、Auth0Provider の子コンポーネントである必要があります。
Expo 53 未満で react-native-auth0 v5.x を使用している バージョン 5.x には Expo 53 以上が必要です。古い Expo バージョンでは v4.x を使用してください。
実機でテストしていない 生体認証(Face ID、指紋認証)はシミュレータでは動作せず、実機のみで動作します。リリース前に必ず実機で認証フロー全体をテストしてください。

関連スキル

  • auth0-quickstart — Auth0 アカウントとアプリケーションのセットアップ
  • auth0-react-native — Bare React Native CLI プロジェクト向け
  • auth0-mfa — 多要素認証の設定
  • auth0-cli — ターミナルから Auth0 リソースを管理

参考リンク

原文(English)を表示

Auth0 Expo Integration

Add authentication to Expo (React Native) applications using react-native-auth0 with the Expo Config Plugin.

Prerequisites

  • Expo SDK 53 or higher (react-native-auth0 v5.x requires Expo 53+)
  • React 19 and React Native 0.78.0 or higher
  • Auth0 account with a Native application configured
  • If Auth0 is not set up yet, use the auth0-quickstart skill first
  • Not compatible with Expo Go — requires custom development client or EAS Build

When NOT to Use

Use Case Recommended Skill
Bare React Native CLI project (no Expo) auth0-react-native
React web SPA (Vite/CRA) auth0-react
Next.js application auth0-nextjs
Vue.js SPA auth0-vue
Angular SPA auth0-angular
Express.js backend auth0-express
Native Android (Kotlin/Java) auth0-android
Backend API (JWT validation) auth0-fastify-api or auth0-express

Quick Start Workflow

1. Configure Auth0

For automated setup with Auth0 CLI, see Setup Guide for complete scripts.

For manual setup, configure a Native application in the Auth0 Dashboard and note your Domain and Client ID.

2. Verify Expo Dev Client

Agent instruction: Before installing the Auth0 SDK, check if the project has expo-dev-client installed. Read the project's package.json and look for expo-dev-client in dependencies or devDependencies.

  • If expo-dev-client is found: Proceed to step 3.

  • If expo-dev-client is NOT found: Use AskUserQuestion with the following message:

    "The react-native-auth0 SDK requires a custom Expo development client — it does not work with Expo Go. Your project does not have expo-dev-client installed.

    How would you like to proceed?

    1. Install it for me — I'll run npx expo install expo-dev-client and continue setup
    2. I'll set it up myself — skip this step and continue to Auth0 SDK installation"

    If the user picks option 1, run:

    npx expo install expo-dev-client
    

    Then proceed to step 3. If option 2, proceed to step 3 directly.

3. Install SDK

npx expo install react-native-auth0

4. Configure Expo Config Plugin

Add the react-native-auth0 plugin to app.json (or app.config.js) with your Auth0 domain and a custom scheme. Also ensure bundleIdentifier (iOS) and package (Android) are set:

{
  "expo": {
    "ios": { "bundleIdentifier": "com.yourcompany.yourapp" },
    "android": { "package": "com.yourcompany.yourapp" },
    "plugins": [
      ["react-native-auth0", {
        "domain": "YOUR_AUTH0_DOMAIN",
        "customScheme": "YOUR_CUSTOM_SCHEME"
      }]
    ]
  }
}

The customScheme must be all lowercase with no special characters (e.g., auth0sample). See Setup Guide for HTTPS callbacks, multiple domains, EAS Build, and secret management.

5. Configure Callback URLs

Add to Allowed Callback URLs and Allowed Logout URLs in the Auth0 Dashboard:

YOUR_CUSTOM_SCHEME://YOUR_AUTH0_DOMAIN/ios/YOUR_BUNDLE_ID/callback,
YOUR_CUSTOM_SCHEME://YOUR_AUTH0_DOMAIN/android/YOUR_PACKAGE/callback

All values must be lowercase with no trailing slash. For HTTPS callback URLs (App Links / Universal Links), see Setup Guide.

6. Add Authentication with Auth0Provider

Wrap your app with Auth0Provider and use the useAuth0 hook:

Agent instruction: Before adding new UI elements, search the project for existing click handlers for login, logout, sign-in, or sign-out buttons. If existing handlers are found, hook the Auth0 code into them. Only create new buttons if no existing handlers are found.

import React from 'react';
import { Auth0Provider, useAuth0 } from 'react-native-auth0';
import { View, Button, Text, ActivityIndicator } from 'react-native';

function HomeScreen() {
  const { authorize, clearSession, user, isLoading, error } = useAuth0();

  const login = async () => {
    try {
      await authorize(
        { scope: 'openid profile email' },
        { customScheme: 'YOUR_CUSTOM_SCHEME' }
      );
    } catch (e) {
      console.error('Login error:', e);
    }
  };

  const logout = async () => {
    try {
      await clearSession({ customScheme: 'YOUR_CUSTOM_SCHEME' });
    } catch (e) {
      console.error('Logout error:', e);
    }
  };

  if (isLoading) {
    return <ActivityIndicator size="large" />;
  }

  return (
    <View>
      {user ? (
        <>
          <Text>Welcome, {user.name}!</Text>
          <Text>{user.email}</Text>
          <Button title="Log Out" onPress={logout} />
        </>
      ) : (
        <Button title="Log In" onPress={login} />
      )}
      {error && <Text>{error.message}</Text>}
    </View>
  );
}

export default function App() {
  return (
    <Auth0Provider
      domain="YOUR_AUTH0_DOMAIN"
      clientId="YOUR_AUTH0_CLIENT_ID"
    >
      <HomeScreen />
    </Auth0Provider>
  );
}

7. Build & Verify

Agent instruction: After completing the integration, build the project to verify it compiles:

npx expo prebuild --clean
npx expo run:ios
# or
npx expo run:android

If the build fails, analyze the error output. Common integration build failures include:

  • "Invariant Violation: Native module cannot be null": Using Expo Go instead of a development build — run npx expo run:ios or npx expo run:android instead of npx expo start
  • Plugin not applied: Missing react-native-auth0 in app.json plugins array — verify the plugin configuration
  • Pod install fails (iOS): Run npx expo prebuild --clean to regenerate native projects
  • Manifest merge failure (Android): Conflicting auth0Domain placeholder — ensure only the config plugin sets the domain

Re-run the build after each fix. Track the number of build-fix iterations.

Failcheck: If the build still fails after 5–6 fix attempts, stop and ask the user using AskUserQuestion: "The build is still failing after several fix attempts. How would you like to proceed?"

  • Let the skill continue fixing iteratively
  • Fix it manually — show the remaining errors
  • Skip build verification — proceed without a successful build

Detailed Documentation

  • Setup Guide — Dev client requirement, automated setup, Expo config plugin, callback URLs, EAS Build, secret management
  • Integration Patterns — Login/logout, credential management, biometric auth, token refresh, organizations, DPoP, error handling
  • API Reference & Testing — Configuration options, useAuth0 hook API, testing checklist, common issues, security

Common Mistakes

Mistake Fix
Using Expo Go instead of development build react-native-auth0 requires native code. Use npx expo run:ios / npx expo run:android or create a development build with EAS.
Missing customScheme in authorize/clearSession calls Pass { customScheme: 'your-scheme' } as the second argument to authorize() and clearSession(). Must match the value in app.json plugin config.
Callback URL mismatch Ensure callback URL is all lowercase, no trailing slash, and matches Auth0 Dashboard exactly: {customScheme}://{domain}/ios/{bundleId}/callback
App type not set to Native The Auth0 application must be type Native in the Dashboard, not SPA or Regular Web.
Missing bundleIdentifier or package in app.json Both expo.ios.bundleIdentifier and expo.android.package must be set in app.json for callback URLs to work.
Forgot to wrap app with Auth0Provider All components using useAuth0() must be children of Auth0Provider.
Using react-native-auth0 v5.x with Expo < 53 Version 5.x requires Expo 53+. Use v4.x for older Expo versions.
Not testing on physical device Biometric authentication (Face ID, fingerprint) only works on a physical device, not simulators. Always test the full auth flow on a real device before release.

Related Skills

References

原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。