0Pricing
Micro Frontends Architecture with Module Federation · บทเรียน

การยืนยันตัวตนและการกำหนดสิทธิ์

สร้างกลไกการยืนยันตัวตนและการกำหนดสิทธิ์ที่แข็งแกร่งสำหรับไมโครฟรอนต์เอนด์ต่าง ๆ

การยืนยันตัวตนและการกำหนดสิทธิ์ เป็นบทเรียน Micro Frontends Architecture with Module Federation ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Micro Frontends Architecture with Module Federation และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Micro Frontends Architecture with Module Federation มีบทเรียนทั้งหมด 4 บทเรียน

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

Auth & Auth in MFEs

Welcome to Authentication & Authorization in Micro Frontends! Securing federated applications brings unique challenges compared to monolithic apps.

We need robust ways to verify user identities (authentication) and control what they can access (authorization) across independently developed and deployed Micro Frontends.

Centralized Authentication Need

In a Micro Frontend architecture, users interact with multiple separate applications. If each MFE handled authentication independently, users would face multiple login prompts.

This leads to a poor user experience and complex session management. A centralized authentication mechanism is crucial for seamless navigation.

Identity Providers (IdP)

A common solution is to use an Identity Provider (IdP). This is a service that creates, maintains, and manages identity information for users and authenticates them.

  • Examples: Auth0, Okta, Keycloak, or a custom OAuth 2.0/OpenID Connect server.
  • The IdP handles the login process and issues security tokens (like JWTs) upon successful authentication.

Authentication Flow Overview

Here's a simplified centralized authentication flow:

  1. User tries to access any MFE.
  2. If not authenticated, they are redirected to the central IdP login page.
  3. User logs in with the IdP.
  4. IdP redirects the user back to the MFE with a security token.
  5. The MFE stores this token (e.g., in an HTTP-only cookie or local storage).

All subsequent requests from any MFE will use this token.

Sharing Authentication State

Once a user is authenticated, their session or token needs to be available to all Micro Frontends. Common strategies for sharing state:

  • HTTP-Only Cookies: Secure and automatically sent with requests.
  • Web Storage (localStorage/sessionStorage): Accessible across same-origin domains.
  • Shared Libraries/Context: A shared utility that wraps token management, often exposed via Module Federation.

Each method has its trade-offs regarding security and ease of implementation.

Authorization Explained

While authentication verifies who you are, authorization determines what you can do.

  • After authentication, the security token often contains user roles or permissions.
  • Each Micro Frontend is then responsible for checking these permissions before granting access to specific features or data.

Role-Based Access Control (RBAC)

Role-Based Access Control (RBAC) is a popular authorization strategy. Users are assigned roles (e.g., 'admin', 'editor', 'viewer'), and each role has specific permissions.

Micro Frontends simply check the user's roles against the required roles for a given action or component.

Implementing Auth Checks

Each Micro Frontend or its backend API can implement authorization checks. This often involves:

  • Decoding the security token to extract user roles/permissions.
  • Comparing these against the required permissions for a specific action or UI element.

Here's a simple JavaScript example:

function hasPermission(userRoles, requiredRole) {
  if (!userRoles || !requiredRole) return false;
  return userRoles.includes(requiredRole);
}

// Imagine user roles are parsed from a JWT
const currentUserRoles = ["user", "editor"]; 

// Check if user can 'edit_post'
const canEdit = hasPermission(currentUserRoles, "editor");

// Check if user can 'delete_user'
const canDelete = hasPermission(currentUserRoles, "admin");

console.log("Can edit post?", canEdit);
console.log("Can delete user?", canDelete);

Security Best Practices

Securing your federated applications requires vigilance:

  • HTTPS: Always use HTTPS for all communication.
  • Token Storage: Store sensitive tokens securely (e.g., HTTP-only cookies over localStorage).
  • CORS: Properly configure Cross-Origin Resource Sharing policies.
  • Input Validation: Always validate user input on both client and server sides.
  • Regular Audits: Perform security audits and keep dependencies updated.

Order the Auth Flow

Drag and drop the steps to correctly order a user's initial authentication flow in a federated application using an Identity Provider (IdP).

Recap: Secure MFEs

We've covered the essentials of authentication and authorization in Micro Frontends. Key takeaways:

  • Centralized authentication via an Identity Provider ensures a smooth user experience.
  • Security tokens (like JWTs) carry authentication and authorization data.
  • Strategies like HTTP-only cookies or shared libraries help share authentication state.
  • Authorization (e.g., RBAC) dictates what users can do, based on roles/permissions in their token.
  • Always follow security best practices like HTTPS and secure token storage.

Next, we'll explore cross-application security risks!

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

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

ใช่ — ข้อความเต็มของ “การยืนยันตัวตนและการกำหนดสิทธิ์” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Micro Frontends Architecture with Module Federation ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Micro Frontends Architecture with Module Federation มีบทเรียนทั้งหมด 4 บทเรียน

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

สร้างกลไกการยืนยันตัวตนและการกำหนดสิทธิ์ที่แข็งแกร่งสำหรับไมโครฟรอนต์เอนด์ต่าง ๆ คุณปฏิบัติ Micro Frontends Architecture with Module Federation ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Micro Frontends Architecture with Module Federation หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Micro Frontends Architecture with Module Federation บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน

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

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

ฉันเขียนและรันโค้ดในบทเรียน Micro Frontends Architecture with Module Federation นี้ได้ไหม

ได้ บทเรียน Micro Frontends Architecture with Module Federation ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

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

  1. การยืนยันตัวตนและการกำหนดสิทธิ์
  2. ความเสี่ยงด้านความปลอดภัยข้ามแอปพลิเคชัน
  3. แนวทางปฏิบัติที่ดีที่สุดสำหรับสหพันธ์ที่ปลอดภัย
  4. การรักษาความปลอดภัยแอประยะไกลของ Module Federation
← กลับไปที่ Micro Frontends Architecture with Module Federation