> ## 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.

> 認可コードフローで Rich Authorization Requests (RAR) を使用する方法を学びます。

# Rich Authorization Requests (RAR) を使用する認可コードフロー

[Rich Authorization Requests (RAR)](https://datatracker.ietf.org/doc/html/draft-ietf-oauth-rar) を使用すると、クライアントは、エンドユーザーなどの <Tooltip tip="リソース所有者: 保護されたリソースへのアクセスを許可できるエンティティ（ユーザーやアプリケーションなど）。" cta="用語集を表示" href="/docs/ja-jp/glossary?term=resource+owners">リソース所有者</Tooltip> から <Tooltip tip="Fine-grained Authorization (FGA): 個々のユーザーに特定のオブジェクトまたはリソースへのアクセスを許可する Auth0 の製品。" cta="用語集を表示" href="/docs/ja-jp/glossary?term=fine-grained+authorization">きめ細かな認可</Tooltip> データを要求し、取得できます。  クライアントは、認可コードフローの一環として、RAR データを Pushed Authorization Request (PAR) エンドポイントに渡すことができます。詳しくは、[Configure Pushed Authorization Requests](/docs/ja-jp/get-started/applications/configure-par) を参照してください。

従来の <Tooltip tip="OAuth 2.0: 認可プロトコルとワークフローを定義する認可フレームワーク。" cta="用語集を表示" href="/docs/ja-jp/glossary?term=OAuth+2.0">OAuth 2.0</Tooltip> フローでは、クライアントが [scopes](/docs/ja-jp/get-started/apis/scopes) を使用して <Tooltip tip="OAuth 2.0: 認可プロトコルとワークフローを定義する認可フレームワーク。" cta="用語集を表示" href="/docs/ja-jp/glossary?term=resource+server">リソースサーバー</Tooltip> へのアクセスをリクエストすると、リソース所有者はクライアントにそれらのリソースへのアクセスを許可します。Rich Authorization Request では、クライアントは `/par` エンドポイントに `authorization_details` パラメーターを渡すことで、scope で要求する権限よりも細かい permissions をリクエストできます。これにより、クライアントとリソース所有者の双方がリソースへのアクセスをよりきめ細かく制御できるようになり、過剰なアクセス権付与に伴うセキュリティリスクを軽減できます。

Auth0 では `authorization_details` の type の検証のみがサポートされているため、`authorization_details` 内の JSON オブジェクトの検証は自分で実装する必要があります。詳しくは、[Rich Authorization Requests を設定する](/docs/ja-jp/get-started/apis/configure-rich-authorization-requests) を参照してください。

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

Rich Authorization Request では、`authorization_details` パラメーターはオブジェクトの JSON 配列で、各オブジェクトには文字列として表される `type` フィールドが含まれている必要があります。`type` フィールドによって、カスタマイズ可能なオブジェクトフィールドが決まります。`authorization_details` 配列には、同じ type のエントリーを複数含めることもできます。`authorization_details` の type を登録する方法について詳しくは、[Rich Authorization Requests を設定する](/docs/ja-jp/get-started/apis/configure-rich-authorization-requests)を参照してください。

Auth0 は、ユーザーがカスタム同意画面で認可できるように `authorization_details` を表示します。詳しくは、[カスタマイズされた同意プロンプトを設定する](/docs/ja-jp/get-started/apis/configure-rich-authorization-requests#set-customized-consent-prompt)を参照してください。

`authorization_details` パラメーターは `/par` エンドポイントに渡す必要があります。これにより、Auth0 の <Tooltip tip="認可サーバー: ユーザーのアクセス範囲の定義に関与する集中型サーバーです。たとえば、認可サーバーはユーザーが利用できるデータ、タスク、機能を制御できます。" cta="用語集を見る" href="/docs/ja-jp/glossary?term=Authorization+Server">認可サーバー</Tooltip> が `type` を事前に検証できるようになります。`/par` エンドポイントは、ブラウザーなどのフロントチャネルで機密データが漏えいするのを防ぐため、認可リクエストをバックチャネルで渡します。認可リクエストを `/par` エンドポイントに渡すと、アプリケーション は `/authorize` エンドポイントにリダイレクトされ、その後、認可コードフローに進みます。詳しくは、[PAR を使用した認可コードフロー](/docs/ja-jp/get-started/authentication-and-authorization-flow/authorization-code-flow/authorization-code-flow-with-par)を参照してください。

認可コードフローを完了するには、次の例のように `/oauth/token` エンドポイントで認可コードを token と交換します。

```http lines theme={null}
POST https://{YOUR_DOMAIN}.auth0.com/oauth/token
Content-Type: application/x-www-form-urlencoded

grant_type=authorization_code&client_id={YOUR_CLIENT_ID}&client_secret={YOUR_CLIENT_SECRET}&code={AUTHORIZATION_CODE}&redirect_uri=https://jwt.io
```

成功すると、<Tooltip tip="アクセストークン: API へのアクセスに使用される、opaqueな文字列または JWT の形式の Authorization 資格情報。" cta="用語集を見る" href="/docs/ja-jp/glossary?term=access+token">アクセストークン</Tooltip> と `authorization_details` 配列を含むレスポンスが返されます：

```json lines theme={null}
{
  "access_token": "ey...ZQ",
  "expires_in": 86400,
  "authorization_details": [
{
  "type": "money_transfer", 
  "instructedAmount": {"amount": 2500, "currency": "USD"},   
  "sourceAccount": "xxxxxxxxxxx1234", 
  "destinationAccount": "xxxxxxxxxxx9876", 
  "beneficiary": "Hanna Herwitz", 
  "subject": "A Lannister Always Pays His Debts"
}
  ],
  "token_type": "Bearer"
}
```

[JWT のベストプラクティス](https://datatracker.ietf.org/doc/html/rfc9068#name-privacy-considerations)の一環として、クライアントは `authorization_details` を使用することで、アクセストークンを確認しなくても、自身に付与された認可のスコープを把握できます。リクエストされた<Tooltip tip="Audience: 発行されたトークンのaudienceの一意な識別子。トークンでは aud という名前で表され、その値には、ID トークンの場合はアプリケーション（Client ID）、アクセストークンの場合は API（API Identifier）の ID が含まれます。" cta="用語集を見る" href="/docs/ja-jp/glossary?term=audience">audience</Tooltip>が [JWE access tokens](/docs/ja-jp/secure/tokens/json-web-tokens) を必要とする API である場合、`/oauth/token` エンドポイントは、`authorization_details` から `type` 以外のすべてのオブジェクトフィールドを省略したレスポンスを返します。レスポンス内のアクセストークンのクレームには影響ありません。

```json lines theme={null}
{
  "iss": "https://my_tenant.auth0.com/",
  "sub": "auth0|me",
  "aud": "https://myapi.authzero.com",
  "iat": 1683661385,
  "exp": 1683747785,
  "azp": "my_client",
  "authorization_details": [
{
  "type": "money_transfer", 
  "instructedAmount": {"amount": 2500, "currency": "USD"},   
  "sourceAccount": "xxxxxxxxxxx1234", 
  "destinationAccount": "xxxxxxxxxxx9876", 
  "beneficiary": "Hanna Herwitz", 
  "subject": "A Lannister Always Pays His Debts"
}
  ]
}
```

<div id="configure-rar-for-the-authorization-code-flow">
  ## 認可コードフロー向けにRARを構成
</div>

認可コードフロー用のRich Authorization Requestsを構成する前に、次の作業を行う必要があります。

* [カスタムドメイン](/docs/ja-jp/customize/custom-domains)を作成します。
* [カスタム Universal Login Pages](/docs/ja-jp/customize/login-pages/universal-login/customize-templates) テンプレートを作成します。<Tooltip tip="アプリケーションは、ユーザーの本人確認のために、Auth0 の認可サーバーでホストされている Universal Login にリダイレクトされます。" cta="用語集を見る" href="/docs/ja-jp/glossary?term=Universal+Login">Universal Login</Tooltip> Page テンプレートをカスタマイズする方法については、[Page templates API](/docs/ja-jp/customize/login-pages/universal-login/customize-templates#page-templates-api) のドキュメントを参照してください。

認可コードフロー向けにRARを構成するには、次の作業が必要です。

* リソースサーバーに `authorization_details` タイプを登録します。
* カスタマイズした同意プロンプトを設定します。

詳しくは、[Rich Authorization Requests を設定する](/docs/ja-jp/get-started/apis/configure-rich-authorization-requests)を参照してください。

<div id="access-authorization_details-in-actions">
  ## Actions で `authorization_details` にアクセスする
</div>

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  Auth0 は、Actions を使用した RAR の更新をサポートしていません。
</Callout>

Auth0 では、[post-login Action](/docs/ja-jp/customize/actions/explore-triggers/signup-and-login-triggers/login-trigger/post-login-event-object) の `event.transaction.requested_authorization_details` プロパティを通じて、`authorization_details` パラメーターを利用できます。Action ではこのプロパティを参照して、[MFA challenge](/docs/ja-jp/secure/highly-regulated-identity/transactional-authorization-with-authorization-code-flow#push-notifications) でユーザーにトランザクションの詳細を表示できます。

<div id="what-doesnt-auth0-support">
  ## Auth0 でサポートされていないこと
</div>

Auth0 では、次のことはサポートされていません。

* Actions を使用した RAR の更新。
* クライアントが検出できるように RAR タイプを公開すること。
* API で許可されているタイプと一致する `type` プロパティを持っているかどうかの確認を超える、RAR オブジェクトの検証。詳細については、[RARを構成](/docs/ja-jp/get-started/apis/configure-rich-authorization-requests) を参照してください。

<div id="learn-more">
  ## 詳細はこちら
</div>

* [Rich Authorization Requests を設定する (RAR)](/docs/ja-jp/get-started/apis/configure-rich-authorization-requests)
