> ## Documentation Index
> Fetch the complete documentation index at: https://translations.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Android および iOS アプリ向けにネイティブのパスキーフローを実装する方法を学びます

# モバイルアプリ向けネイティブパスキー

export const ReleaseStageNotice = ({feature, stage, plans, contact, terms}) => {
  const stageTextMap = {
    "beta": "ベータ",
    "ea": "早期アクセス"
  };
  const stageText = stageTextMap[stage] || "製品リリース段階";
  const prsLink = "/docs/troubleshoot/product-lifecycle/product-release-stages";
  const linkify = (text, url) => {
    return <a href={url} target="_blank" rel="noreferrer" class="link">{text}</a>;
  };
  const includeDetails = (plans, contact, terms) => {
    const hasDetails = terms || plans || contact;
    if (!hasDetails) return null;
    return <span data-as="p">
            {plans && <>この機能は、{linkify(`${plans}プラン`, "https://auth0.com/pricing")}で利用できます。 </>}
            {contact && "参加するには、" + contact + " までお問い合わせください。 "}
            {terms && <>この機能を使用すると、Okta の{linkify("Master Subscription Agreement", "https://www.okta.com/legal")}に定める該当する無料トライアル条件に同意したものとみなされます。</>}
        </span>;
  };
  return <Warning>
            <span data-as="p">
                <strong>{feature} 機能は現在、{linkify(stageText, prsLink)}です。</strong>
            </span>

            {includeDetails(plans, contact, terms)}
        </Warning>;
};

<ReleaseStageNotice feature="Native Passkeys" stage="ea" terms="true" />

パスキーは、従来の認証手段 (ユーザー名とパスワードなど) に代わる、フィッシングに強い認証方式です。より簡単で安全なユーザー体験を提供し、FIDO® W3C Web Authentication (WebAuthn) および Client to Authenticator Protocol (CTAP) の[仕様](https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-errata-20220621.html#intro)に基づいています。

Auth0 は現在、データベース接続の認証方法としてパスキーをサポートしており、次の 2 つの実装方法を提供しています。

* Web ベースのアプリケーション向けの[Universal Login passkeys](/ja/docs/authenticate/database-connections/passkeys)
* Android および iOS アプリケーション向けの ネイティブパスキー。
* Web ベースおよびネイティブアプリケーション向けの[Embedded Login](/ja/docs/authenticate/passwordless/implement-login/embedded-login)

<div id="how-it-works">
  ## 仕組み
</div>

ネイティブパスキーでは、[Auth0 Authentication API](/ja/docs/authenticate/database-connections/passkeys/native-passkeys-api) と iOS または Android のネイティブ API を組み合わせて使用し、チャレンジフローをモバイルアプリケーションに直接組み込みます。これにより、認証完了のためにユーザーをブラウザにリダイレクトしなくても、アプリケーションに統合されたサインアップおよびログイン体験を実現できます。

以下の例は、新規ユーザーがパスキーのサインアップフローでどのような体験をする可能性があるかを示しています。

1. 新規ユーザーがモバイルアプリケーションを起動し、ログイン画面を開きます。新規ユーザーのため、Sign Up ボタンを選択します。
2. 次の画面で、ユーザーはメールアドレスを入力し、Create Account を選択します。
3. 次に、ユーザーはアプリケーション用のパスキーを作成するかどうか確認されます。続行するには、Continue を選択します。
4. パスキーを生成するには、ユーザーは生体認証や PIN の入力などの認証方法を使って、デバイス上でローカル認証を行う必要があります。
5. ローカル認証が完了すると、新しいパスキーがユーザーのデバイスに保存され、iCloud や Google などのパスキープロバイダーと同期されます。
6. パスキーが保存されると、ユーザーは新規ユーザー登録プロセスを続け、アカウント作成を完了します。

このプロセスが完了すると、ユーザーは次回アプリケーションにログインするときに、保存したパスキーを使って認証できます。

<div id="before-you-begin">
  ## 始める前に
</div>

<div id="configure-a-custom-domain">
  ### カスタムドメインを設定する
</div>

ネイティブパスキーを使用するには、<Tooltip tip="Custom Domain: 専用の、いわゆるバニティ名を持つサードパーティ製ドメイン。" cta="用語集を見る" href="/ja/docs/glossary?term=custom+domain">カスタムドメイン</Tooltip>が必要です。続行する前に、テナントにカスタムドメインが設定されていることを確認してください。詳細については、[Custom Domains](/ja/docs/customize/custom-domains)を参照してください。

<div id="configure-your-passkey-policy">
  ### パスキーポリシーを設定する
</div>

Android または iOS アプリケーションでネイティブパスキーを実装する前に、Auth0 テナントでパスキーポリシーを設定する必要があります。テナントを準備するには、[パスキーポリシーを設定する](/ja/docs/authenticate/database-connections/passkeys/configure-passkey-policy) の手順に従ってください。

<div id="prepare-your-application">
  ### アプリケーションを準備する
</div>

アプリケーションでネイティブパスキーを利用できるようにするには、Device Settings を構成し、`Passkey` グラントを追加する必要があります。これらの設定は、<Tooltip tip="Auth0 Dashboard: サービスを設定するための Auth0 の主要製品。" cta="用語集を見る" href="/ja/docs/glossary?term=Auth0+Dashboard">Auth0 Dashboard</Tooltip>または<Tooltip tip="Management API: お客様が管理タスクを実行できるようにする製品。" cta="用語集を見る" href="/ja/docs/glossary?term=Management+API">Management API</Tooltip>で行えます。

<div id="associated-domains">
  #### 関連ドメイン
</div>

エンドユーザーが異なるアプリケーションタイプ間、またはサブドメインが異なるアプリケーションタイプ間で、1つのパスキーを使って認証できるようにするには、Relying Party ID をルートドメインまたは親ドメインに設定します。詳しくは、[Passkeys](/ja/docs/authenticate/database-connections/passkeys) を参照してください。

<div id="configure-auth0-dashboard">
  ### Auth0 Dashboard を設定する
</div>

1. [Applications > Applications](https://manage.auth0.com/#/applications) に移動し、更新するアプリケーションを選択します。
2. Settings タブの下部にある **Advanced Settings** を選択し、次に **Device Settings** タブを選択します。
3. アプリケーションに応じて **iOS** と **Android** の各セクションを設定し、**Save Changes** をクリックします。
4. Advanced Settings セクションで、**Grant Types** タブを選択します。
5. **Passkey** グラント を有効にし、**Save Changes** を選択します。

<div id="management-api">
  #### Management API
</div>

[Update a Client](https://auth0.com/docs/api/management/v2/clients/patch-clients-by-id) エンドポイントを呼び出し、次の操作を行います。

* `grant_types` を更新し、`urn:okta:params:oauth:grant-type:webauthn` を含めます。
* 必要に応じて、`mobile` オブジェクトを使用して iOS および Android デバイスの設定を指定します。

<div id="implement-passkey-flows">
  ## パスキーフローを実装する
</div>

アプリケーションでは、次のパスキーフローを定義できます。

* [サインアップフロー](#signup-flow): ユーザー登録時に、新規ユーザーがパスキーを生成して保存できるようにします。
* [ログインフロー](#login-flow): すでにパスキーを登録済みの既存ユーザーが、ログイン時に保存済みのパスキーで認証できるようにします。

<div id="signup-flow">
  ### サインアップフロー
</div>

ユーザーが初めてアプリケーションへのログインを試みると、パスキーのサインアップフローが開始されます。

ユーザーが既存の識別子を入力した場合は、代わりにログインフローを完了するよう案内することをおすすめします。そうしないと、その操作は失敗します。

<div id="flow-steps">
  #### フローの手順
</div>

1. ユーザーがアプリケーションにアクセスし、新しいアカウントの登録を選択します。ユーザーは、メールアドレスなど、アプリケーションで求められた識別子を入力します。
2. 次に、アプリケーションは Auth0 Authentication API の [Request Signup Challenge](/ja/docs/authenticate/database-connections/passkeys/native-passkeys-api#request-signup-challenge) エンドポイントを呼び出して、サインアップチャレンジを開始します。

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  * `realm` を指定しない場合は、テナントのデフォルトディレクトリが使用されます。
  * デフォルトでは、必須の識別子はメールアドレスです。データベース接続で [Flexible Identifiers](/ja/docs/authenticate/database-connections/activate-and-configure-attributes-for-flexible-identifiers) を有効にしている場合は、代わりに `email`、`phone_number`、`username` の組み合わせを使用できます。これらのオプションは必須にも任意にも設定でき、Flexible Identifier の設定と一致している必要があります。
</Callout>

```text lines theme={null}
   POST /passkey/register
   Content-Type: application/json

   {
     "client_id": "{YOUR_CLIENT_ID}",
     "realm": "{OPTIONAL_CONNECTION}",
     "user_profile": {
   	  "email": "{VALID_EMAIL_ADDRESS}",
   	  "name": "{OPTIONAL_USER_DISPLAY_NAME}",
     }
   }
```

3. これに対して、Auth0 は [`PublicKeyCredentialCreationOptions`](https://www.w3.org/TR/webauthn-3/#dictdef-publickeycredentialcreationoptions) を、`auth_session` ID および `rp.id` としての `rpId` とともに返します。

   ```text lines expandable theme={null}
   HTTP/1.1 200 OK
   Content-Type: application/json

   {
     "authn_params_public_key": {
       "challenge": "{GENERATED_CHALLENGE_FOR_THIS_SESSION}",
       "timeout": {MILLISECONDS},
       "rp": {
         "id": "{YOUR_CUSTOM_DOMAIN}",
         "name": "{YOUR_CUSTOM_DOMAIN}"
       },
       "pubKeyCredParams": [
         { type: 'public-key', alg: -8 },
         { type: 'public-key', alg: -7 },
         { type: 'public-key', alg: -257 }
       ],
       "authenticatorSelection": {
         "residentKey": "required",
         "userVerification": "preferred"
       },
       "user": {
         "id": "{GENERATED_ID}",
         "name": "{USER-ENTERED_IDENTIFIER}",
         "displayName": "{USER-ENTERED_DISPLAY_NAME_OR_IDENTIFIER_IF_MISSING}"
       }
     },
     "auth_session": "{SESSION_ID}"
    }
   ```

   <Callout icon="file-lines" color="#0EA5E9" iconType="regular">
     レスポンスで返される `rpId` は、関連ドメインでパスキーを機能させるために Web フローで使用されるドメインと一致します。
   </Callout>

4. 次に、アプリケーションは適切なネイティブ API を使用して、ユーザー登録プロセスを完了します。

   * [Android の登録に関するドキュメント](https://developer.android.com/identity/passkeys/create-passkeys)を確認してください。
   * [iOS の登録に関するドキュメント](https://developer.apple.com/documentation/authenticationservices/supporting-passkeys#Register-a-new-account-on-a-service)を確認してください。

5. 次に、アプリケーションは登録プロセスで取得した認証情報 (`authn_response` の詳細を含む) を使用して、[Token](/ja/docs/authenticate/database-connections/passkeys/native-passkeys-api#authenticate-new-user) エンドポイントを呼び出します。

   ```text lines theme={null}
   POST /oauth/token
   Content-Type: application/json

   {
     "grant_type": "urn:okta:params:oauth:grant-type:webauthn",
     "client_id": "{YOUR_CLIENT_ID}",
     "realm": "{OPTIONAL_CONNECTION}",
     "scope": "{OPTIONAL_REQUESTED_SCOPE}",
     "audience": "{OPTIONAL_REQUESTED_AUDIENCE}"
     "auth_session": "{SESSION_ID_FROM_THE_FIRST_REQUEST}",
     "authn_response": {
       "id": "{BASE64URL_ID}",
       "rawId": "{BASE64URL_RAWID}",
       "type": "public-key",
       "authenticatorAttachment": "platform|cross-platform",
       "response": {
         "clientDataJSON": "{BASE64URL_CLIENT_DATA_JSON}",
         "attestationObject": "{BASE64URL_ATTESTATION_OBJECT}",
         {OTHER_PROPERTIES}
       },
     },
   }
   ```

6. Auth0 は新しいユーザーアカウントを作成し、要求されたトークンを返してフローを完了します。

   ```text lines theme={null}
   HTTP/1.1 200 OK
   Content-Type: application/json

   {
     "access_token": "{BASE64_TOKEN}",
     "refresh_token": "{BASE64_TOKEN}",
     "id_token": "{BASE64_TOKEN}",
     "token_type": "Bearer",
     "expires_in": {SECONDS}
   }
   ```

<div id="login-flow">
  ### ログインフロー
</div>

既存ユーザーがアプリケーションへのログインを試みると、パスキーによるログインフローが開始されます。このフローは、初回登録時にアカウントにパスキーを保存した既存ユーザーにのみ適用されます。

<div id="flow-steps">
  #### フローの手順
</div>

1. ユーザーがアプリケーションを起動してログインを開始すると、アプリケーションは Authentication API の [Request Login Challenge](/ja/docs/authenticate/database-connections/passkeys/native-passkeys-api#request-login-challenge) エンドポイントを呼び出して、ログインチャレンジを開始します。

   <Callout icon="file-lines" color="#0EA5E9" iconType="regular">
     `realm` を指定しない場合は、テナントのデフォルトディレクトリが使用されます。
   </Callout>

   ```text lines theme={null}
   POST /passkey/challenge
   Content-Type: application/json

   {
     "client_id": "{YOUR_CLIENT_ID}",
     "realm": "{OPTIONAL_CONNECTION}"
   }
   ```

2. これに対し、Auth0 は [`PublicKeyCredentialRequestOptions`](https://www.w3.org/TR/webauthn-3/#dictdef-publickeycredentialrequestoptions) と、アプリケーション内でフローを継続するための `auth_session` を返します。

   ```text lines theme={null}
   HTTP/1.1 200 OK
   Content-Type: application/json

   {
     "authn_params_public_key": {
       "challenge": "{GENERATED_CHALLENGE_FOR_THIS_SESSION}",
       "timeout": {AUTH_TIMEOUT_IN_MILLISECONDS},
       "rpId": "{CUSTOM_DOMAIN}",
       "userVerification": "preferred"
     },
     "auth_session": "{SESSION_ID}"
   }
   ```

3. 次に、アプリケーションは適切なネイティブ API を使用してログイン処理を完了します。

   * [Android のログインに関するドキュメント](https://developer.android.com/identity/passkeys/sign-in-with-passkeys)を参照してください。
   * [iOS のログインに関するドキュメント](https://developer.apple.com/documentation/authenticationservices/supporting-passkeys#Connect-to-a-service-with-an-existing-account)を参照してください。

4. 次に、アプリケーションはログイン処理で取得した認証情報 (`authn_response` の詳細を含む) を使用して、[Token](/ja/docs/authenticate/database-connections/passkeys/native-passkeys-api#authenticate-existing-user) エンドポイントを呼び出します。

   ```text lines theme={null}
   POST /oauth/token
   Content-Type: application/json

   {
     "grant_type": "urn:okta:params:oauth:grant-type:webauthn",
     "client_id": "{YOUR_CLIENT_ID}",
     "realm": "{OPTIONAL_CONNECTION}",
     "scope": "{OPTIONAL_REQUESTED_SCOPE}",
     "audience": "{OPTIONAL_REQUESTED_AUDIENCE}"
     "auth_session": "{SESSION_ID_FROM_THE_FIRST_REQUEST}",
     "authn_response": {
       "id": "{BASE64URL_ID}",
       "rawId": "{BASE64URL_RAWID}",
       "type": "public-key",
       "authenticatorAttachment": "platform|cross-platform",
       "response": {
         "authenticatorData": "{BASE64URL_AUTHENTICATORDATA}",
         "clientDataJSON": "{BASE64URL_CLIENTDATAJSON}",
         "signature": "{BASE64URL_SIGNATURE}",
         "userHandle": "{BASE64URL_USERHANDLE}"
       },
       "clientExtensionResults": {OPTIONAL_OBJECT}
      }
   }
   ```

5. Auth0 は認証情報を検証し、要求されたトークンを返してフローを完了します。

   ```text lines theme={null}
   HTTP/1.1 200 OK
   Content-Type: application/json

   {
     "access_token": "{BASE64_TOKEN}",
     "refresh_token": "{BASE64_TOKEN}",
     "id_token": "{BASE64_TOKEN}",
     "token_type": "Bearer",
     "expires_in": {SECONDS}
   }
   ```

<div id="references">
  ## 参考資料
</div>

モバイルアプリケーションにネイティブパスキーを実装する際は、以下のリソースを参照してください。

* Auth0 Authentication API

  * [サインアップチャレンジをリクエストする](/ja/docs/authenticate/database-connections/passkeys/native-passkeys-api#request-signup-challenge)
  * [新規ユーザーを認証する](/ja/docs/authenticate/database-connections/passkeys/native-passkeys-api#authenticate-new-user)
  * [ログインチャレンジをリクエストする](/ja/docs/authenticate/database-connections/passkeys/native-passkeys-api#request-login-challenge)
  * [既存ユーザーを認証する](/ja/docs/authenticate/database-connections/passkeys/native-passkeys-api#authenticate-existing-user)
* Android のリソース

  * [登録に関するドキュメント](https://developer.android.com/identity/passkeys/create-passkeys)
  * [ログインに関するドキュメント](https://developer.android.com/identity/passkeys/sign-in-with-passkeys)
* iOS のリソース

  * [登録に関するドキュメント](https://developer.apple.com/documentation/authenticationservices/supporting-passkeys#Register-a-new-account-on-a-service)
  * [ログインに関するドキュメント](https://developer.apple.com/documentation/authenticationservices/supporting-passkeys#Connect-to-a-service-with-an-existing-account)
