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

> シングルページアプリケーション（SPA）向けの Management API トークンで利用できるスコープとエンドポイントについて説明します。

# シングルページアプリケーション向けの Management API アクセストークン を取得する

場合によっては、Auth0 Management Dashboard ではなく、Auth0 の [Management API](https://auth0.com/docs/api/management/v2#!) を使ってアプリケーションや API を管理したいことがあります。

<Tooltip tip="Management API: お客様が管理タスクを実行できるようにする製品です。" cta="用語集を見る" href="/docs/ja-jp/glossary?term=Management+API">Management API</Tooltip> のエンドポイントを呼び出すには、Management API トークン と呼ばれる専用の [Access Token](/docs/ja-jp/secure/tokens/access-tokens) を使用して認証する必要があります。Management API Tokens は、呼び出す Management API エンドポイントに対して付与された特定の権限 (scopes とも呼ばれます) を含む [JSON Web Tokens (JWTs)](/docs/ja-jp/secure/tokens/json-web-tokens) です。

<h2 id="limitations">
  制限事項
</h2>

シングルページアプリケーション (SPA) は<Tooltip tip="パブリッククライアント: 資格情報を安全に保持できないクライアント（アプリケーション）。例としては、ネイティブのデスクトップまたはモバイルアプリケーション、JavaScript ベースのクライアントサイド Web アプリケーション（シングルページアプリ（SPA）など）が含まれます。" cta="用語集を見る" href="/docs/ja-jp/glossary?term=public+clients">パブリッククライアント</Tooltip>であり、機密情報 (**<Tooltip tip="クライアントシークレット: クライアント（アプリケーション）が Authorization Server で認証するために使用する秘密情報。これはクライアントと Authorization Server のみが知っているべきものであり、推測できないよう十分にランダムでなければなりません。" cta="用語集を見る" href="/docs/ja-jp/glossary?term=Client+Secret">Client Secret</Tooltip>** など) を安全に保存できないため、他の[アプリケーションの種類](/docs/ja-jp/get-started/applications)とは異なり、Management API トークン はフロントエンドから取得する必要があります。つまり、SPA 向けの Management API トークン には一定の制限があります。具体的には、これらのトークンは現在 Auth0 にサインインしているユーザーのコンテキストで発行されるため、更新できるのはログイン中のユーザー自身のデータに限られます。このため Management API の用途は制限されますが、ログイン中のユーザーのユーザープロファイルを更新する操作には引き続き利用できます。

<Warning>
  Auth0 は、ユーザーが user metadata を変更できる Management API トークン をフロントエンドに置くことを推奨していません。これにより、ユーザーが自身の metadata を操作して、アプリケーションの動作に悪影響を及ぼすおそれがあります。また、大量のリクエストを送ってレート制限に達させるだけで、他のユーザーの management API に対して DoS 攻撃を仕掛けられてしまう可能性もあります。
</Warning>

<h2 id="available-scopes-and-endpoints">
  利用可能なスコープとエンドポイント
</h2>

SPA 向けに発行された Management API トークン を使用すると、以下のスコープ (および対応するエンドポイント) にアクセスできます。

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  [PATCH /api/v2/users/{id}](https://auth0.com/docs/api/management/v2#!/Users/patch_users_by_id) エンドポイントを使用したパスワード変更は、SPA 向けに発行された Management API トークン では **実行できません**。
</Callout>

| 現在のユーザー向けスコープ                            | エンドポイント                                                                                                                                                                                                                                                  |
| ---------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `read:current_user`                      | [GET /api/v2/users/{id}](https://auth0.com/docs/api/management/v2#!/Users/get_users_by_id)<br />[GET /api/v2/users/{id}/enrollments](https://auth0.com/docs/api/management/v2#!/Users/get_enrollments)                                                   |
| `update:current_user_identities`         | [POST/api/v2/users/{id}/identities](https://auth0.com/docs/api/management/v2#!/Users/post_identities)<br />[DELETE /api/v2/users/{id}/identities/{provider}/{user_id}](https://auth0.com/docs/api/management/v2#!/Users/delete_user_identity_by_user_id) |
| `update:current_user_metadata`           | [PATCH /api/v2/users/{id}](https://auth0.com/docs/api/management/v2#!/Users/patch_users_by_id)                                                                                                                                                           |
| `create:current_user_metadata`           | [PATCH /api/v2/users/{id}](https://auth0.com/docs/api/management/v2#!/Users/patch_users_by_id)                                                                                                                                                           |
| `create:current_user_device_credentials` | [POST /api/v2/device-credentials](https://auth0.com/docs/api/management/v2#!/Device_Credentials/post_device_credentials)                                                                                                                                 |
| `delete:current_user_device_credentials` | [DELETE /api/v2/device-credentials/{id}](https://auth0.com/docs/api/management/v2#!/Device_Credentials/delete_device_credentials_by_id)                                                                                                                  |

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  上記のスコープとエンドポイントには、[レート制限](/docs/ja-jp/troubleshoot/customer-support/operational-policies/rate-limit-policy) が適用されます。
</Callout>

<h2 id="use-management-api-token-to-call-management-api-from-a-spa">
  SPA から Management API を呼び出すための Management API トークンの使用
</h2>

SPA から Management API トークンを取得し (生成には Management API の <Tooltip tip="Audience: 発行されたトークンの対象を一意に識別する識別子です。トークンでは aud という名前で表され、その値には、ID Token の場合は application（Client ID）、Access Token の場合は API（API Identifier）の ID が含まれます。" cta="用語集を見る" href="/docs/ja-jp/glossary?term=audience">audience</Tooltip> を使用) 、そのトークンを使って Management API を呼び出すことで、現在ログインしているユーザーの完全なユーザープロファイルを取得できます。

1. [Management API トークンを取得する](/docs/ja-jp/secure/tokens/access-tokens/management-api-access-tokens/get-management-api-access-tokens-for-production)。

   1. ユーザーを Authorization エンドポイントにリダイレクトして認証します。これは、ユーザーがログインまたはサインアップ時に移動する先です。
   2. Management API トークンを受け取ると、[JSON Web Token 形式](/docs/ja-jp/secure/tokens/json-web-tokens/json-web-token-structure) になっています。
   3. トークンをデコードし、その内容を確認します。
2. Management API を呼び出して、[Get User by ID](https://auth0.com/docs/api/management/v2#!/Users/get_users_by_id) エンドポイントからログイン中のユーザーのユーザープロファイルを取得します。

   1. エンドポイントを呼び出すには、取得したエンコード済みの Management API トークンをリクエストの `Authorization` ヘッダーに含めます。
   2. `USER_ID` と `MGMT_API_ACCESS_TOKEN` のプレースホルダー値は、それぞれログイン中のユーザーのユーザー ID (デコードした Management API トークンの `sub` の値) と Management API access token に置き換えてください。

<h2 id="learn-more">
  詳しくはこちら
</h2>

* [テスト用の Management API アクセストークンを取得する](/docs/ja-jp/secure/tokens/access-tokens/management-api-access-tokens/get-management-api-access-tokens-for-testing)
* [本番環境用の Management API アクセストークンを取得する](/docs/ja-jp/secure/tokens/access-tokens/management-api-access-tokens/get-management-api-access-tokens-for-production)
