Skip to content

Conversation

@gowthamsundaresan
Copy link

@gowthamsundaresan gowthamsundaresan commented Sep 25, 2025

JWT Flow:

  ┌─────────────────────────────────────────────────────────────┐
  │                     API Call Request                        │
  └──────────────────────┬──────────────────────────────────────┘
                         ▼
                ┌────────────────┐
                │ getValidJWT()  │
                └───────┬────────┘
                        ▼
              ┌──────────────────┐     No
              │  JWT exists?     ├────────► "Please login"
              └────────┬─────────┘
                       │ Yes
                       ▼
              ┌──────────────────┐     Yes    ┌──────────────┐
              │  JWT expired?    ├───────────►│ refreshToken │
              └────────┬─────────┘            └──────┬───────┘
                       │ No                           │
                       ▼                              ▼
           ┌────────────────────┐            ┌────────────────┐
           │ Return valid JWT   │            │Refresh success?│
           └──────────┬─────────┘            └───┬────────┬───┘
                      │                          Yes       No
                      ▼                           │         │
           ┌────────────────────┐                 │         ▼
           │ Make API request   │◄────────────────┘    ┌──────────┐
           │ with Bearer token  │                      │clearAuth()│
           └──────────┬─────────┘                      └─────┬────┘
                      ▼                                      │
           ┌────────────────────┐                            ▼
           │ Response status?   │                      "Please login"
           └──┬──────────┬──────┘
              │          │
           200-399    401/403
              │          │
              ▼          ▼
         ┌────────┐  ┌──────────────┐
         │Success │  │refreshToken()│
         └────────┘  └──────┬───────┘
                            ▼
                    ┌────────────────┐     No     ┌──────────┐
                    │Refresh success?├───────────►│clearAuth()│
                    └───────┬────────┘            └─────┬────┘
                            │ Yes                        │
                            ▼                            ▼
                    ┌────────────────┐            "Please login"
                    │ Retry API call │
                    └──────┬─────────┘
                           ▼
                    ┌────────────────┐
                    │Response status?│
                    └──┬──────────┬──┘
                       │          │
                    200-399    401/403
                       │          │
                       ▼          ▼
                  ┌────────┐  ┌──────────┐
                  │Success │  │clearAuth()│
                  └────────┘  └─────┬────┘
                                    │
                                    ▼
                              "Please login"

  JWKS Verification Flow:

  ┌──────────────────────────────────────────┐
  │         New JWT Received                 │
  │    (from login or refresh)               │
  └─────────────────┬────────────────────────┘
                    ▼
           ┌─────────────────┐
           │ Get JWKS        │
           └────────┬────────┘
                    ▼
          ┌──────────────────┐       No      ┌─────────────┐
          │ JWKS cached?     ├──────────────►│ Fetch JWKS  │
          └────────┬─────────┘               │ from server │
                   │ Yes                     └──────┬──────┘
                   ▼                                │
          ┌──────────────────┐                      │
          │ Cache < 1hr old? │                      │
          └────────┬─────────┘                      │
                   │ No                             │
                   └────────────────────────────────┤
                                                    │
                                                    ▼
                                           ┌─────────────────┐
                                           │ Verify JWT with │
                                           │ JWKS public key │
                                           └────────┬────────┘
                                                    ▼
                                           ┌─────────────────┐
                                           │      Valid?     │
                                           └───┬─────────┬───┘
                                              Yes        No
                                               │          │
                                               ▼          ▼
                                          Store JWT   Return null

@gowthamsundaresan gowthamsundaresan marked this pull request as ready for review September 29, 2025 06:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants