Book

OAuth 2.1のしくみと実装 — Better Auth OAuth Providerをソースから読み解く

OAuthの役割分担からAuthorization Code + PKCE、Refresh Token、Client Credentials、Device Flow、OIDC、BFF、DPoPまでを、React・Hono・Better Authの実装とデータベース観測を往復しながら学びます。

28 chapters 無料公開 #oauth#openid-connect#better-auth#react#hono

Part 1

Part 1 OAuthを構成要素から組み立てる

用語、信頼境界、実験環境、Authorization Serverの土台を揃えます。

  1. Chapter 1

    OAuthを『ログイン機能』として始めない

  2. Chapter 2

    4つのroleと、越えてはいけない信頼境界

  3. Chapter 3

    React + Honoで観測可能なOAuthラボを作る

  4. Chapter 4

    Better AuthをAuthorization Serverとして構成する

Part 2

Part 2 Authorization Code + PKCEを一周する

認可要求からResource APIまでを追い、失敗系で安全性を確かめます。

  1. Chapter 5

    Authorization Requestを組み立てる

  2. Chapter 6

    ASのログインsessionとOAuth transactionを分離する

  3. Chapter 7

    Consentをscopeの契約として実装する

  4. Chapter 8

    Authorization Codeを一回限りの引換券にする

  5. Chapter 9

    PKCEでCodeを開始したClientへ結び付ける

  6. Chapter 10

    Opaque Access TokenをResource APIで検証する

  7. Chapter 11

    成功するE2Eより先に攻撃を失敗させる

Part 3

Part 3 TokenとGrantを使い分ける

Refresh、JWT、機械間通信、入力制約のある端末を比較します。

  1. Chapter 12

    Refresh Tokenで認可を継続する

  2. Chapter 13

    Rotationとreuse detectionでToken familyを守る

  3. Chapter 14

    Resource IndicatorとJWT Access Tokenを結び付ける

  4. Chapter 15

    Client Credentialsで機械自身を認可する

  5. Chapter 16

    Device Authorizationで別端末へ認可を委ねる

  6. Chapter 17

    GrantをprincipalとClient能力から選ぶ

Part 4

Part 4 OAuthの上にOIDCを重ねる

認可と認証を分離し、ID Token、UserInfo、Logoutを検証します。

  1. Chapter 18

    OAuthとOpenID Connectを混ぜずに重ねる

  2. Chapter 19

    ID Tokenを署名・claim・at_hashまで検証する

  3. Chapter 20

    DiscoveryとUserInfoの信頼連鎖を作る

  4. Chapter 21

    Logoutを三つの状態の終了として設計する

Part 5

Part 5 実運用の境界を強くする

BFF、Client認証、登録、DPoP、PARの設計境界を扱います。

  1. Chapter 22

    Next.js + Hono BFFへToken所有権を移す

  2. Chapter 23

    Client認証をnone・secret・private_key_jwtで比較する

  3. Chapter 24

    Client登録を管理APIとDCRに分ける

  4. Chapter 25

    DPoPでAccess TokenをClient keyへ束縛する

  5. Chapter 26

    PARをProviderのrequest_uri resolver境界で理解する

Part 6

Part 6 配備と適合性を検証する

Cloudflareへの移行と、仕様適合性を継続して示す方法を整理します。

  1. Chapter 27

    NodeラボをCloudflare Workersへ移す

  2. Chapter 28

    仕様適合性を継続して示す