0Pricing
System Design Basics for Backend Developers · บทเรียน

การยืนยันตัวตนและการอนุญาตสิทธิ์

นำกลไกการยืนยันตัวตนและการอนุญาตสิทธิ์ที่รัดกุมมาใช้ เพื่อควบคุมการเข้าถึงทรัพยากรของระบบ

การยืนยันตัวตนและการอนุญาตสิทธิ์ เป็นบทเรียน System Design Basics for Backend Developers ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน System Design Basics for Backend Developers และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส System Design Basics for Backend Developers มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Auth vs. Auth: The Basics

In system design, authentication and authorization are critical for security. They control who can access your system and what they can do.

  • Authentication (AuthN) verifies who you are.
  • Authorization (AuthZ) determines what you're allowed to do.

Think of it like a club: authentication is checking your ID at the door, authorization is seeing if you have a VIP pass to enter special areas.

What is Authentication?

Authentication is the process of proving your identity to a system. This confirms that you are who you claim to be.

Common authentication methods include:

  • Password-based: Username and password.
  • Multi-factor: Combining passwords with codes from an app or SMS.
  • Biometric: Fingerprints or facial recognition.
  • Token-based: Using a cryptographic token after initial login.

Token-Based Authentication

Token-based authentication is popular for web and mobile apps. After a user logs in (authenticates) with credentials, the server issues a token.

This token is then sent with every subsequent request to prove the user's identity without sending credentials repeatedly. A common type is the JSON Web Token (JWT).

Understanding JWTs

A JWT (JSON Web Token) is a compact, URL-safe means of representing claims to be transferred between two parties. It's often used to authenticate users.

JWTs consist of three parts, separated by dots:

  1. Header: Type of token and signing algorithm.
  2. Payload: Claims (user ID, roles, expiration).
  3. Signature: Used to verify the token hasn't been tampered with.

It looks something like this:

eyJhbGciOiJIUzI1NiJ9.eyJ1c2VySWQiOiIxMjMiLCJyb2xlIjoiYWRtaW4ifQ.SFLS...

Simple Token Check Demo

When a client sends a request with a token, the server must validate it. This often involves checking the signature and expiration.

Here's a very simplified conceptual example of how a server might check if a token is known, representing a basic validation step:

public class TokenChecker {
  public static void main(String[] args) {
    String userToken = "validUserToken123";
    String adminToken = "adminSecretToken456";
    String invalidToken = "badToken";

    System.out.println("User Token Check: " + isValid(userToken));
    System.out.println("Admin Token Check: " + isValid(adminToken));
    System.out.println("Invalid Token Check: " + isValid(invalidToken));
  }

  // A very simplified conceptual token validation
  public static boolean isValid(String token) {
    if (token.equals("validUserToken123") || token.equals("adminSecretToken456")) {
      return true; // Token is conceptually 'valid'
    }
    return false; // Token is not recognized
  }
}

What is Authorization?

Authorization is the process of determining what an authenticated user or system is permitted to do.

For example, a regular user might be able to view their own profile, but only an administrator can delete user accounts. Authorization answers the question: "Are you allowed to do that?"

Role-Based Access Control (RBAC)

One common authorization model is Role-Based Access Control (RBAC). In RBAC, permissions are associated with roles, and users are assigned to roles.

  • Users: Individuals or systems.
  • Roles: Collections of permissions (e.g., 'Admin', 'Editor', 'Viewer').
  • Permissions: Specific actions on resources (e.g., 'read_post', 'edit_user').

This simplifies managing access, as you assign users to roles rather than individual permissions.

Policy-Based Authorization

For more complex scenarios, Policy-Based Authorization (like Attribute-Based Access Control or ABAC) allows for very fine-grained control.

Instead of just roles, access decisions are based on attributes of the user, the resource, the environment, and the action itself. This offers greater flexibility but can be more complex to manage.

AuthN and AuthZ Together

Authentication and authorization work hand-in-hand in a typical request flow:

  1. A user tries to access a resource.
  2. The system authenticates the user (e.g., validates their token). If invalid, access is denied.
  3. If authenticated, the system then authorizes the user: it checks if the user's role or attributes grant them permission for that specific action on that resource.
  4. If authorized, access is granted. Otherwise, it's denied.

Identify the Concepts

Which of the following statements correctly describe the concepts of Authentication and Authorization?

Recap: Securing Access

We've explored the crucial difference between authentication (who you are) and authorization (what you can do).

You learned about token-based authentication with JWTs and authorization models like RBAC. Understanding these concepts is fundamental to designing secure and robust systems.

Keep practicing these distinctions as you design systems that need to control access effectively!

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

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

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

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

นำกลไกการยืนยันตัวตนและการอนุญาตสิทธิ์ที่รัดกุมมาใช้ เพื่อควบคุมการเข้าถึงทรัพยากรของระบบ คุณปฏิบัติ System Design Basics for Backend Developers ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน System Design Basics for Backend Developers หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน System Design Basics for Backend Developers บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน

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

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

ฉันเขียนและรันโค้ดในบทเรียน System Design Basics for Backend Developers นี้ได้ไหม

ได้ บทเรียน System Design Basics for Backend Developers ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

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

  1. การยืนยันตัวตนและการอนุญาตสิทธิ์
  2. การเข้ารหัสข้อมูลและความเป็นส่วนตัว
  3. การป้องกัน DDoS และไฟร์วอลล์
  4. การจำกัดอัตราและการควบคุมความเร็ว
← กลับไปที่ System Design Basics for Backend Developers