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

> 認可コードフローの仕組みと、従来型Webアプリケーションでこれを使用すべき理由を学びます。

# 認可コードフロー

認可コードフロー ([OAuth 2.0 RFC 6749, section 4.1](https://tools.ietf.org/html/rfc6749#section-4.1)で定義) は、認可コードをトークンに交換するフローです。

このフローは、交換時にアプリケーションの認証情報も含まれ、それを安全に保つ必要があるため、機密性のあるアプリケーション (従来型Webアプリケーションなど) でのみ使用できます。

<div id="how-authorization-code-flow-works">
  ## 認可コードフローの仕組み
</div>

<Frame>
  <img src="https://mintcdn.com/translations/c0RQ9V0YAcT0-8l5/docs/images/cdy7uua7fh8z/7mWk9No612EefC8uBidCqr/821eb60b0aa953b0d8e4afe897228844/Auth-code-flow-diagram.png?fit=max&auto=format&n=c0RQ9V0YAcT0-8l5&q=85&s=95d3ef4044beef76aaa5a16a4558ee41" alt="Auth - Auth code flow- Authorization sequence diagram" width="1400" height="877" data-path="docs/images/cdy7uua7fh8z/7mWk9No612EefC8uBidCqr/821eb60b0aa953b0d8e4afe897228844/Auth-code-flow-diagram.png" />
</Frame>

1. ユーザーがアプリケーション内で **Login** を選択します。
2. Auth0 の SDK がユーザーを Auth0 Authorization Server ([`/authorize`](https://auth0.com/docs/api/authentication/authorization-code-flow/authorize-application) エンドポイント) にリダイレクトします。
3. Auth0 Authorization Server がユーザーをログイン画面と認可プロンプトにリダイレクトします。
4. ユーザーは設定されたログイン方法のいずれかで認証を行い、Auth0 がアプリケーションに付与する権限の一覧が表示された同意プロンプトが表示される場合があります。
5. Auth0 Authorization Server は、1 回限り有効な認可コードとともにユーザーをアプリケーションにリダイレクトします。
6. Auth0 の SDK は、認可コード、アプリケーションの client ID、および client secret や Private Key JWT などのアプリケーションの資格情報を Auth0 Authorization Server ([`/oauth/token`](https://auth0.com/docs/api/authentication/authorization-code-flow/get-token) エンドポイント) に送信します。
7. Auth0 Authorization Server は、認可コード、アプリケーションの client ID、およびアプリケーションの資格情報を検証します。
8. Auth0 Authorization Server は、ID トークンとアクセストークン (必要に応じてリフレッシュトークンも) を返します。
9. アプリケーションはアクセストークンを使って API を呼び出し、ユーザーに関する情報にアクセスできます。
10. API は要求されたデータを返します。

<div id="how-to-implement-authorization-code-flow">
  ## 認可コードフローを実装する方法
</div>

認可コードフローを実装する最も簡単な方法は、[Regular Web App Quickstarts](/docs/ja-jp/quickstart/webapp) に従うことです。

また、Authentication API を使用して認可コードフローを実装することもできます。詳細については、[認可コードフローを使用した Login の追加](/docs/ja-jp/get-started/authentication-and-authorization-flow/authorization-code-flow/add-login-auth-code-flow) または [認可コードフローを使用した API の呼び出し](/docs/ja-jp/get-started/authentication-and-authorization-flow/authorization-code-flow/call-your-api-using-the-authorization-code-flow) をご覧ください。

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  Origin ヘッダーを含むブラウザーアプリケーションが `/oauth/token` エンドポイントに `POST` リクエストを送信した場合、アプリケーションで [Refresh Tokenのローテーションを許可](/docs/ja-jp/secure/tokens/refresh-tokens/configure-refresh-token-rotation) が有効になっており、[offline\_access](/docs/ja-jp/secure/tokens/refresh-tokens/configure-refresh-token-rotation#configure-with-the-auth0-spa-sdk) スコープを送信していても、Auth0 はリフレッシュトークンを発行しません。
</Callout>

<div id="learn-more">
  ## さらに詳しく
</div>

* [Auth0 ルール](/docs/ja-jp/customize/rules)
* [Auth0 フック](/docs/ja-jp/customize/hooks)
* [トークン](/docs/ja-jp/secure/tokens)
* [トークンのベストプラクティス](/docs/ja-jp/secure/tokens/token-best-practices)
* [どの OAuth 2.0 フローを使用すべきですか？](/docs/ja-jp/get-started/authentication-and-authorization-flow/which-oauth-2-0-flow-should-i-use)
