> ## Documentation Index
> Fetch the complete documentation index at: https://auth0.com/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アプリケーションなど) でのみ使用できます。

## 認可コードフローの仕組み

![Auth - Auth code flow- Authorization sequence diagram](https://mintlify.s3.us-west-1.amazonaws.com/auth0/docs/images/cdy7uua7fh8z/7mWk9No612EefC8uBidCqr/821eb60b0aa953b0d8e4afe897228844/Auth-code-flow-diagram.png)

1. ユーザーがアプリケーション内で **Login** を選択します。
2. Auth0 の SDK がユーザーを Auth0 Authorization Server ([`/authorize`](https://auth0.com/docs/ja-jp/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/ja-jp/api/authentication/authorization-code-flow/get-token) エンドポイント) に送信します。
7. Auth0 Authorization Server は、認可コード、アプリケーションの client ID、およびアプリケーションの資格情報を検証します。
8. Auth0 Authorization Server は、ID トークンとアクセストークン (必要に応じてリフレッシュトークンも) を返します。
9. アプリケーションはアクセストークンを使って API を呼び出し、ユーザーに関する情報にアクセスできます。
10. API は要求されたデータを返します。

## 認可コードフローを実装する方法

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

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

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

## さらに詳しく

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