Authorization Code Flow
WebサーバーアプリケーションのようなConfidential Clientに適した、安全性が高く広く使われているフローを習得します。
「Authorization Code Flow」はCoddyKit上の無料OAuth2 & OpenID Connect Deep Diveレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはOAuth2 & OpenID Connect Deep Dive学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 OAuth2 & OpenID Connect Deep Diveコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Auth Code Flow: The Secure Standard
Welcome to the Authorization Code Flow lesson! This is the most secure and widely adopted OAuth2 flow, especially for web applications.
It's designed to protect sensitive credentials and is the go-to choice for clients that can keep a secret, known as confidential clients.
Why Confidential Clients?
A confidential client is an application (like a traditional web server app) that can securely store a secret, such as a client_secret.
This flow relies on a secure, direct communication channel between your application's backend and the Authorization Server, keeping sensitive tokens away from the user's browser.
The Four Roles in Action
Recall the four key roles in OAuth2:
- Resource Owner: The user granting access.
- Client: Your application requesting access.
- Authorization Server: Verifies identity and issues tokens.
- Resource Server: Holds the protected data.
In this flow, they interact in a specific, multi-step dance.
Step 1: Requesting Authorization
It all starts when the Resource Owner (user) wants to log in or grant access to your Client application.
Your application redirects the user's browser to the Authorization Server's authorization endpoint, including several parameters:
response_type=code(crucial!)client_id(your app's ID)redirect_uri(where to send the user back)scope(permissions requested)state(for security, explained later)
Step 2: User Grants Consent
Once redirected to the Authorization Server, the user sees a consent screen.
This screen asks the user if they agree to grant your Client application the requested permissions (defined by scope).
The user can then choose to Approve or Deny the request.
Step 3: Authorization Code Delivery
If the user approves, the Authorization Server redirects the user's browser back to the redirect_uri you provided in Step 1.
This redirect URL now includes a one-time use authorization code and the state parameter you sent, for example:
https://your-app.com/callback?code=AUTH_CODE_HERE&state=RANDOM_STRINGThis code is short-lived and doesn't grant direct access to resources.
Step 4: Exchanging Code for Tokens
This is where the magic happens! Your Client application's backend (server-side) receives the authorization code.
It then makes a direct, back-channel HTTP POST request to the Authorization Server's token endpoint.
This request includes the code, redirect_uri, client_id, and crucially, your client_secret to authenticate your application.
Step 5: Tokens Issued
The Authorization Server validates the request, especially the client_secret and the code.
If everything is valid, it issues an access token and, optionally, a refresh token to your Client application's backend.
Your application can now use the access token to make requests to the Resource Server on behalf of the user.
Protecting Against CSRF with `state`
The state parameter is a critical security measure against Cross-Site Request Forgery (CSRF) attacks.
Your Client should generate a unique, cryptographically random string for each authorization request and include it as the state parameter.
When the Authorization Server redirects back, it includes this same state. Your Client must then verify that the returned state matches the one it sent, ensuring the callback is legitimate.
Ideal Use Cases
The Authorization Code Flow is best suited for:
- Confidential Clients: Especially web server applications.
- Clients with a backend: Where the
client_secretcan be securely stored and used. - Public Clients with PKCE: (Covered in a later lesson) Mobile apps and SPAs can use it with an extension called PKCE for enhanced security.
It's the most robust choice when security is paramount.
Flow Checkpoint
Consider the steps of the Authorization Code Flow. Which of these parameters are typically sent by the client to the Authorization Server's token endpoint during the token exchange step?
Recap: Authorization Code Flow
You've mastered the Authorization Code Flow!
- It's the most secure OAuth2 flow.
- Ideal for confidential clients (server-side apps).
- Uses a temporary authorization code to exchange for tokens.
- The token exchange happens securely via a back-channel (server-to-server).
- The
stateparameter protects against CSRF.
This flow forms the foundation for many secure authentication and authorization systems.
よくある質問
「Authorization Code Flow」レッスンは無料ですか?
はい。「Authorization Code Flow」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、OAuth2 & OpenID Connect Deep Diveコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 OAuth2 & OpenID Connect Deep Diveコースには全4レッスンが含まれています。
「Authorization Code Flow」で何を学びますか?
WebサーバーアプリケーションのようなConfidential Clientに適した、安全性が高く広く使われているフローを習得します。 ブラウザで直接実行するハンズオンコードでOAuth2 & OpenID Connect Deep Diveを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
OAuth2 & OpenID Connect Deep Diveを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのOAuth2 & OpenID Connect Deep Diveは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。
「Authorization Code Flow」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このOAuth2 & OpenID Connect Deep Diveレッスンでコードを書いて実行できますか?
はい。すべてのOAuth2 & OpenID Connect Deep Diveレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- Authorization Code Flow
- Client Credentials Flow
- Implicit Flowと非推奨化
- デバイス認可グラント