OAuth2 & OpenID Connect Deep Dive · درس

بنية رمز ID وتوقيعه

فكّكوا ترويسة رمز ID (JWT) وحمولته وتوقيعه، وتعرّفوا إلى كيفية توقيعه والمعلومات التي يحتويها.

الدرس 1 من 411 خطوة

بنية رمز ID وتوقيعه درس مجاني في OAuth2 & OpenID Connect Deep Dive على CoddyKit. هذا هو الدرس 1 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في OAuth2 & OpenID Connect Deep Dive، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة OAuth2 & OpenID Connect Deep Dive 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

Meet the ID Token

In OpenID Connect (OIDC), the ID Token is a crucial piece of information. It's a security token that contains claims about the authentication of an end-user by an Authorization Server.

Think of it as a digital ID card for the user, issued after they successfully log in.

ID Tokens Are JWTs

ID Tokens are always formatted as JSON Web Tokens (JWTs). A JWT is a compact, URL-safe means of representing claims to be transferred between two parties.

Every JWT has three main parts, separated by dots:

  • Header
  • Payload
  • Signature

The Header: What Algorithm?

The first part of an ID Token is the Header. It's a JSON object that describes the token itself, like what type of token it is and the algorithm used to sign it.

  • alg: The cryptographic algorithm used for signing (e.g., RS256, HS256).
  • typ: The type of token, which is usually "JWT".

Header in Action

When you decode the base64url-encoded header, you'll see a JSON object like this. This tells you how the token was secured.

{
"alg": "RS256",
"typ": "JWT",
"kid": "someKeyId"
}

The kid (Key ID) helps find the correct public key for verification.

Decoding Header Example

The header is base64url encoded. Here's how you might decode a JWT header string in Java. This helps reveal its content.

import java.util.Base64;
import java.nio.charset.StandardCharsets;

public class JwtDecoder {
  public static void main(String[] args) {
    String encodedHeader = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6InNvbWVLZXlJZCJ9";
    byte[] decodedBytes = Base64.getUrlDecoder().decode(encodedHeader);
    String decodedString = new String(decodedBytes, StandardCharsets.UTF_8);
    System.out.println("Decoded Header:");
    System.out.println(decodedString);
  }
}

The Payload: Claims About You

The second part is the Payload. This is where the actual "claims" about the user and the authentication event are stored. Claims are statements about an entity (typically the user).

Standard claims you'll often see include:

  • iss: Issuer (who issued the token).
  • sub: Subject (unique identifier for the user).
  • aud: Audience (who the token is for).
  • exp: Expiration Time (when the token expires).
  • iat: Issued At Time (when the token was issued).

Payload in Action

Similar to the header, the payload is also a base64url-encoded JSON object. It contains the identity information you need.

{
"iss": "https://example.com/auth",
"sub": "user123",
"aud": "myAppClientId",
"exp": 1678886400,
"iat": 1678882800,
"name": "Alice Wonderland"
}

exp and iat are Unix timestamps.

The Signature: Ensuring Trust

The third and final part is the Signature. This is critical for security! It's used to verify that the token hasn't been tampered with and that it comes from a legitimate issuer.

The signature is created by taking the encoded header, the encoded payload, and a secret key or private key, and running them through the cryptographic algorithm specified in the header.

Verifying the Signature

When your application receives an ID Token, it uses the public key (provided by the Issuer) to verify the signature. It re-computes the signature using the header, payload, and the public key.

If the re-computed signature matches the token's signature, you can trust that:

  • The token hasn't been altered.
  • It was issued by the expected Authorization Server.

Quick Check on JWT

You've learned that ID Tokens are structured as JWTs, with three distinct parts. Each part plays a vital role in conveying and securing user identity information.

Recap: ID Token Anatomy

Great job! You now understand the fundamental structure of an ID Token.

  • Header: Describes the token and signing algorithm.
  • Payload: Contains identity claims about the user.
  • Signature: Ensures the token's integrity and authenticity.

Each part is base64url encoded and separated by dots, forming a secure and verifiable digital identity for the user.

البدء مجانًا

تعلم OAuth2 & OpenID Connect Deep Dive مع معلم ذكاء اصطناعي — مجانًا

اكتب وقم بتشغيل أكوادك الفعلية في المتصفح، واحصل على مساعدة فورية من معلم ذكاء اصطناعي متاح 24/7، واستمر من حيث توقفت على الويب أو في التطبيق.

الدورات
12
الدروس
48

الأسئلة الشائعة

هل درس «بنية رمز ID وتوقيعه» مجاني؟

نعم — نص درس «بنية رمز ID وتوقيعه» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة OAuth2 & OpenID Connect Deep Dive، انتقل إلى CoddyKit PRO. تتضمن دورة OAuth2 & OpenID Connect Deep Dive 4 دروس في المجموع.

ماذا ستتعلم في «بنية رمز ID وتوقيعه»؟

فكّكوا ترويسة رمز ID (JWT) وحمولته وتوقيعه، وتعرّفوا إلى كيفية توقيعه والمعلومات التي يحتويها. تتمرن على OAuth2 & OpenID Connect Deep Dive مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ OAuth2 & OpenID Connect Deep Dive؟

لا تُشترط خبرة سابقة. OAuth2 & OpenID Connect Deep Dive على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 1 من أصل 4.

كم من الوقت يستغرق درس «بنية رمز ID وتوقيعه»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس OAuth2 & OpenID Connect Deep Dive هذا؟

نعم. كل درس في OAuth2 & OpenID Connect Deep Dive يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. بنية رمز ID وتوقيعه
  2. JWS ومجموعات JWK
  3. إلغاء الرموز والاستبطان
  4. التحقق من مطالبات رمز ID القياسية
← العودة إلى OAuth2 & OpenID Connect Deep Dive