رموز الوصول ورموز التحديث والنطاقات
افهموا الرموز التي يصدرها OAuth2، وكيف تحافظ رموز التحديث على استمرار الجلسات، وكيف تحدد النطاقات ما يمكن للرمز تنفيذه.
رموز الوصول ورموز التحديث والنطاقات درس مجاني في OAuth2 & OpenID Connect Deep Dive على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في OAuth2 & OpenID Connect Deep Dive، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة OAuth2 & OpenID Connect Deep Dive 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Tokens Are the Currency of OAuth2
After a successful flow, OAuth2 hands the client a token instead of the user's credentials. The client presents this token to the resource server to access protected data.
The Access Token
An access token is a short-lived credential proving the client may call an API on the user's behalf. It is sent on each request, usually in the Authorization header.
GET /api/profile
Authorization: Bearer eyJhbGciOi...Why Tokens Expire
Access tokens are deliberately short-lived (minutes to an hour). If one leaks, the window of misuse is small. But forcing the user to re-login constantly would be painful.
The Refresh Token
A refresh token is a longer-lived credential the client uses to obtain new access tokens without bothering the user. It is stored securely and never sent to APIs.
Refreshing in Practice
When the access token expires, the client posts the refresh token to the token endpoint and receives a fresh access token.
POST /oauth/token
grant_type=refresh_token
&refresh_token=def502...
&client_id=my-appWhat Scopes Are
Scopes declare exactly what a token may do, such as read:profile or write:orders. They implement least privilege at the token level.
scope=read:profile write:ordersRequesting Scopes
The client requests scopes during authorization. The user consents, and the issued token is limited to the granted scopes, no more.
GET /authorize?response_type=code
&client_id=my-app
&scope=read:profile
&redirect_uri=https://app/cbEnforcing Scopes
The resource server checks that the token carries the scope an endpoint requires. A token with only read:profile is rejected from a write endpoint.
if (!token.getScopes().contains("write:orders")) {
return forbidden();
}Reference vs Self-Contained
An access token may be a random reference the server looks up, or a self-contained JWT carrying claims the server validates by signature without a lookup.
Revoking Tokens
Refresh tokens can be revoked to end a session, for example on logout or suspected compromise. This invalidates the ability to mint new access tokens.
POST /oauth/revoke
token=def502...
&token_type_hint=refresh_tokenToken Storage Matters
Store tokens carefully: never in plain localStorage for sensitive apps, keep refresh tokens server-side or in secure storage, and always use HTTPS in transit.
Quick Check
An access token has expired but you do not want the user to log in again. What does the client use to get a new one?
Recap
You learned how OAuth2 tokens work:
- Access tokens are short-lived and sent to APIs
- Refresh tokens silently obtain new access tokens
- Scopes enforce least privilege per token
- Tokens can be reference-based or JWTs
- Revocation and secure storage protect sessions
These concepts underpin every OAuth2 grant type you will study next.
تعلم OAuth2 & OpenID Connect Deep Dive مع معلم ذكاء اصطناعي — مجانًا
اكتب وقم بتشغيل أكوادك الفعلية في المتصفح، واحصل على مساعدة فورية من معلم ذكاء اصطناعي متاح 24/7، واستمر من حيث توقفت على الويب أو في التطبيق.
- الدورات
- 12
- الدروس
- 48
الأسئلة الشائعة
هل درس «رموز الوصول ورموز التحديث والنطاقات» مجاني؟
نعم — نص درس «رموز الوصول ورموز التحديث والنطاقات» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة OAuth2 & OpenID Connect Deep Dive، انتقل إلى CoddyKit PRO. تتضمن دورة OAuth2 & OpenID Connect Deep Dive 4 دروس في المجموع.
ماذا ستتعلم في «رموز الوصول ورموز التحديث والنطاقات»؟
افهموا الرموز التي يصدرها OAuth2، وكيف تحافظ رموز التحديث على استمرار الجلسات، وكيف تحدد النطاقات ما يمكن للرمز تنفيذه. تتمرن على OAuth2 & OpenID Connect Deep Dive مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ OAuth2 & OpenID Connect Deep Dive؟
لا تُشترط خبرة سابقة. OAuth2 & OpenID Connect Deep Dive على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «رموز الوصول ورموز التحديث والنطاقات»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس OAuth2 & OpenID Connect Deep Dive هذا؟
نعم. كل درس في OAuth2 & OpenID Connect Deep Dive يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- OAuth2: بروتوكول التفويض
- أدوار OAuth2 ومصطلحاته
- نظرة عامة على أنواع المنح الأساسية
- رموز الوصول ورموز التحديث والنطاقات