OAuth2 & OpenID Connect Deep Dive · レッスン

Refresh TokenとScope

再認証なしで新しいAccess Tokenを取得するRefresh Tokenと、アクセス権限を定義するScopeの役割を学習します。

レッスン 2/411 ステップ

「Refresh TokenとScope」はCoddyKit上の無料OAuth2 & OpenID Connect Deep Diveレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはOAuth2 & OpenID Connect Deep Dive学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 OAuth2 & OpenID Connect Deep Diveコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Keep Your Apps Authorized

Imagine using an app that needs to access your online photos. It gets permission, but what if that permission expires after just an hour?

You'd have to log in again and grant permission every single time! That's not a great user experience, is it?

The Short Life of Access Tokens

Access tokens are like temporary keys. They grant access to specific resources (like your photos) for a short time, often minutes or hours.

This short lifespan is a crucial security feature. If an access token is stolen, an attacker has a limited window to use it, reducing potential damage.

Introducing Refresh Tokens

To solve the constant re-login problem, OAuth2 uses refresh tokens. Think of them as a special, long-term key.

An application uses a refresh token to quietly request a brand new access token from the Authorization Server without needing you to re-enter your credentials.

The Refresh Process

When your access token expires, the client application sends its refresh token to the Authorization Server. This happens in the background.

If the refresh token is valid, the server issues a new access token (and sometimes a new refresh token too!). Your app continues working seamlessly.

public class RefreshExample {
  public static void main(String[] args) {
    System.out.println("1. Access token expires.");
    System.out.println("2. Client sends refresh token.");
    System.out.println("3. Authorization Server validates.");
    System.out.println("4. New access token issued.");
    System.out.println("5. App continues without re-login.");
  }
}

Protecting Refresh Tokens

Since refresh tokens can grant new access tokens, they are very powerful and must be protected carefully. They are more sensitive than access tokens.

  • Store securely: Encrypt them or keep them in secure, HTTP-only cookies.
  • Revoke: If compromised, they must be immediately revoked by the user or server.
  • Limited use: Some systems issue new refresh tokens with each refresh, invalidating the old one.

What Are Scopes?

Now let's talk about scopes. Scopes are simple strings that define the exact permissions an application is requesting from you.

They control *what* an application can do with your resources once it has an access token. Think of them as permission labels, like 'read_email' or 'write_photos'.

How Scopes are Applied

When an app asks for your permission (during the authorization step), it will explicitly list the scopes it needs.

You, the resource owner, then decide which of those permissions to grant. For example, you might grant 'read_profile' but deny 'write_posts'.

Practical Scope Examples

Scopes are typically defined by the Resource Server, and their names can vary. Here are some common examples you might encounter:

  • openid: Requesting basic identity info (often used in OpenID Connect).
  • profile: Access to your basic profile data (name, picture, etc.).
  • email: Access to your primary email address.
  • https://www.googleapis.com/auth/photos.readonly: Read-only access to Google Photos.

Scopes Persist on Refresh

When an application uses a refresh token to get a new access token, the new access token will generally carry the same scopes that were originally granted.

The application can't magically gain new permissions during a refresh; it must request them again through a full user authorization flow if it needs more access.

Quick Check: Tokens & Scopes

Which of the following statements about Refresh Tokens and Scopes are TRUE?

Summary: Refresh & Scopes

We've covered two vital OAuth2 concepts that enhance both security and user experience:

  • Refresh Tokens: Long-lived credentials used to obtain new, short-lived access tokens without user interaction, improving UX.
  • Scopes: Granular permissions that define what an application is authorized to do on a user's behalf.

Understanding these helps you build more secure and user-friendly applications!

無料で開始

AI チューターと学ぶ OAuth2 & OpenID Connect Deep Dive — 無料

ブラウザでリアルコードを書いて実行し、24/7 の AI チューターから瞬時にサポートを受け、ウェブまたはアプリで続きから学習できます。

コース
12
レッスン
48

よくある質問

「Refresh TokenとScope」レッスンは無料ですか?

はい。「Refresh TokenとScope」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、OAuth2 & OpenID Connect Deep Diveコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 OAuth2 & OpenID Connect Deep Diveコースには全4レッスンが含まれています。

「Refresh TokenとScope」で何を学びますか?

再認証なしで新しいAccess Tokenを取得するRefresh Tokenと、アクセス権限を定義するScopeの役割を学習します。 ブラウザで直接実行するハンズオンコードでOAuth2 & OpenID Connect Deep Diveを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

OAuth2 & OpenID Connect Deep Diveを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのOAuth2 & OpenID Connect Deep Diveは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。

「Refresh TokenとScope」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このOAuth2 & OpenID Connect Deep Diveレッスンでコードを書いて実行できますか?

はい。すべてのOAuth2 & OpenID Connect Deep Diveレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. Public Client向けPKCE
  2. Refresh TokenとScope
  3. Resource Owner Password Credentials
  4. トークン交換(RFC 8693)
← OAuth2 & OpenID Connect Deep Diveに戻る