Access Tokens, Refresh Tokens & Scopes
Verstehen Sie, welche Tokens OAuth2 ausstellt, wie Refresh Tokens Sitzungen aktiv halten und wie Scopes die möglichen Aktionen eines Tokens einschränken.
Access Tokens, Refresh Tokens & Scopes ist eine kostenlose OAuth2 & OpenID Connect Deep Dive-Lektion auf CoddyKit. Dies ist Lektion 4 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des OAuth2 & OpenID Connect Deep Dive-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der OAuth2 & OpenID Connect Deep Dive-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
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.
Häufig gestellte Fragen
Ist die Lektion „Access Tokens, Refresh Tokens & Scopes“ kostenlos?
Ja — der vollständige Text von „Access Tokens, Refresh Tokens & Scopes“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des OAuth2 & OpenID Connect Deep Dive-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der OAuth2 & OpenID Connect Deep Dive-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Access Tokens, Refresh Tokens & Scopes“?
Verstehen Sie, welche Tokens OAuth2 ausstellt, wie Refresh Tokens Sitzungen aktiv halten und wie Scopes die möglichen Aktionen eines Tokens einschränken. Du übst OAuth2 & OpenID Connect Deep Dive mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um OAuth2 & OpenID Connect Deep Dive zu starten?
Keine Vorkenntnisse erforderlich. OAuth2 & OpenID Connect Deep Dive auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 4 von 4.
Wie lange dauert die Lektion „Access Tokens, Refresh Tokens & Scopes“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser OAuth2 & OpenID Connect Deep Dive-Lektion Code schreiben und ausführen?
Ja. Jede OAuth2 & OpenID Connect Deep Dive-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- OAuth2: Das Delegationsprotokoll
- OAuth2-Rollen und -Terminologie
- Überblick über die wichtigsten Grant Types
- Access Tokens, Refresh Tokens & Scopes