0Pricing
OAuth2 & OpenID Connect Deep Dive · บทเรียน

โฟลว์รหัสอนุญาตสิทธิ์

เชี่ยวชาญโฟลว์ที่ปลอดภัยและใช้กันอย่างแพร่หลายที่สุด ซึ่งเหมาะสำหรับไคลเอ็นต์ที่เก็บข้อมูลลับได้ เช่น แอปพลิเคชันเว็บเซิร์ฟเวอร์

โฟลว์รหัสอนุญาตสิทธิ์ เป็นบทเรียน OAuth2 & OpenID Connect Deep Dive ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน 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_STRING

This 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_secret can 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 state parameter protects against CSRF.

This flow forms the foundation for many secure authentication and authorization systems.

คำถามที่พบบ่อย

บทเรียน “โฟลว์รหัสอนุญาตสิทธิ์” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “โฟลว์รหัสอนุญาตสิทธิ์” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส OAuth2 & OpenID Connect Deep Dive ให้อัปเกรดเป็น CoddyKit PRO คอร์ส OAuth2 & OpenID Connect Deep Dive มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “โฟลว์รหัสอนุญาตสิทธิ์”

เชี่ยวชาญโฟลว์ที่ปลอดภัยและใช้กันอย่างแพร่หลายที่สุด ซึ่งเหมาะสำหรับไคลเอ็นต์ที่เก็บข้อมูลลับได้ เช่น แอปพลิเคชันเว็บเซิร์ฟเวอร์ คุณปฏิบัติ OAuth2 & OpenID Connect Deep Dive ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน OAuth2 & OpenID Connect Deep Dive หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน OAuth2 & OpenID Connect Deep Dive บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน

บทเรียน “โฟลว์รหัสอนุญาตสิทธิ์” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน OAuth2 & OpenID Connect Deep Dive นี้ได้ไหม

ได้ บทเรียน OAuth2 & OpenID Connect Deep Dive ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. โฟลว์รหัสอนุญาตสิทธิ์
  2. โฟลว์ข้อมูลรับรองไคลเอ็นต์
  3. โฟลว์แบบแฝงและการเลิกใช้งาน
  4. การมอบสิทธิ์อุปกรณ์
← กลับไปที่ OAuth2 & OpenID Connect Deep Dive