isa-auth 0.1.0 β†’ 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,199 @@
1
+ ---
2
+ name: isa-auth-guide
3
+ description: Complete developer and architecture guide for using and extending the isa-auth multi-provider authentication framework, covering OAuth (Google, Apple, Meta, Line, Kakao, Naver), Developer (GitHub, Discord), Web3 (SIWE), Identity (World ID Orb, Passkey WebAuthn), reactive store, Axios/Fetch interceptors, and RBAC/ABAC guards.
4
+ ---
5
+
6
+ # ISA-AUTH Comprehensive Guide & Developer Skill
7
+
8
+ This skill provides full reference, architecture details, and copy-paste recipes for working with the `isa-auth` suite.
9
+
10
+ ---
11
+
12
+ ## πŸ“Œ 1. Architecture & Provider Taxonomy
13
+
14
+ `isa-auth` is a **zero-Node-dependency, framework-agnostic client authentication suite** published under the single package `isa-auth`.
15
+
16
+ ### 4 Provider Categories
17
+ | Category | Providers | Key Features |
18
+ | :--- | :--- | :--- |
19
+ | **`social`** | Google, Apple, Meta/Facebook, Kakao, Naver, LINE | Native SDK wrappers, OpenID Connect, OAuth 2.0 PKCE |
20
+ | **`developer`** | GitHub, Discord | Developer OAuth 2.0 PKCE, Bot/Server authorization |
21
+ | **`web3`** | Ethereum SIWE (EIP-4361) | EIP-1193 wallet detection, `personal_sign` signature |
22
+ | **`identity`** | World ID (Orb), Passkey (WebAuthn/FIDO2) | ZK-SNARK Proof of Personhood, Face ID / Touch ID / Windows Hello |
23
+
24
+ ---
25
+
26
+ ## πŸš€ 2. Code Recipes
27
+
28
+ ### Recipe 0: Multi-Provider All-in-One Configuration (Recommended)
29
+ ```typescript
30
+ import { IsaAuth } from 'isa-auth';
31
+
32
+ // 1. Initialize multiple providers simultaneously
33
+ const auth = new IsaAuth({
34
+ storage: 'memory', // Production security default
35
+ providers: {
36
+ google: { clientId: 'GOOGLE_CLIENT_ID', callbackUrl: 'https://myapp.com/callback' },
37
+ kakao: { clientId: 'KAKAO_JAVASCRIPT_KEY', callbackUrl: 'https://myapp.com/callback' },
38
+ apple: { clientId: 'com.myapp.service', callbackUrl: 'https://myapp.com/callback' },
39
+ github: { clientId: 'GITHUB_CLIENT_ID', callbackUrl: 'https://myapp.com/callback' },
40
+ passkey: { rpName: 'My Enterprise App', rpId: 'myapp.com' },
41
+ },
42
+ });
43
+
44
+ // 2. Trigger individual provider login
45
+ await auth.signIn('kakao');
46
+ // or
47
+ await auth.signIn('google');
48
+
49
+ // 3. Render buttons: individual or all at once
50
+ auth.renderButton('github', document.getElementById('gh-slot'));
51
+ auth.renderAllButtons(document.getElementById('social-login-grid'), {
52
+ direction: 'grid', // 'grid' | 'column' | 'row'
53
+ gap: '12px',
54
+ });
55
+
56
+ // 4. Query registered providers
57
+ console.log(auth.getRegisteredProviders()); // ['google', 'kakao', 'apple', 'github', 'passkey']
58
+ ```
59
+
60
+ ### Recipe A: World ID (World Network / Orb Verification)
61
+ ```typescript
62
+ import { IsaAuth } from 'isa-auth';
63
+
64
+ const worldAuth = new IsaAuth({
65
+ provider: 'world',
66
+ clientId: 'app_staging_your_app_id',
67
+ extraOptions: {
68
+ action: 'vote',
69
+ verificationLevel: 'orb', // 'orb' (Biometric iris scan) or 'device'
70
+ signal: 'user_wallet_0x123',
71
+ onSuccess: (proof) => {
72
+ console.log('ZK Proof generated:', proof.nullifier_hash, proof.proof);
73
+ },
74
+ },
75
+ });
76
+
77
+ await worldAuth.signIn();
78
+ const userInfo = await worldAuth.getUserInfo();
79
+ // { id: '0x...', isHuman: true, verificationLevel: 'orb', ... }
80
+ ```
81
+
82
+ ### Recipe B: Passkey (FIDO2 / WebAuthn Biometrics)
83
+ ```typescript
84
+ import { IsaAuth } from 'isa-auth';
85
+
86
+ const passkeyAuth = new IsaAuth({
87
+ provider: 'passkey',
88
+ extraOptions: {
89
+ rpName: 'My Financial App',
90
+ rpId: window.location.hostname,
91
+ userName: 'alice@example.com',
92
+ },
93
+ });
94
+
95
+ // Authenticate via Face ID / Touch ID / Windows Hello
96
+ await passkeyAuth.signIn();
97
+
98
+ // Register new biometric credential
99
+ await passkeyAuth.providerInstance.registerCredential();
100
+ ```
101
+
102
+ ### Recipe C: Axios Interceptor with Automatic 401 Refresh & Queue
103
+ ```typescript
104
+ import axios from 'axios';
105
+ import { IsaAuth } from 'isa-auth';
106
+
107
+ const auth = new IsaAuth({ provider: 'jwt' });
108
+ const apiClient = axios.create({ baseURL: 'https://api.example.com' });
109
+
110
+ // Applies Authorization: Bearer <token> & deduplicated 401 token refresh queue
111
+ auth.applyAxiosInterceptor(apiClient, {
112
+ refreshFn: async () => {
113
+ const res = await axios.post('/api/auth/refresh');
114
+ return res.data.accessToken;
115
+ },
116
+ onUnauthorized: () => {
117
+ window.location.href = '/login';
118
+ },
119
+ });
120
+ ```
121
+
122
+ ### Recipe D: Backend Token Exchange Adapter
123
+ ```typescript
124
+ import { IsaAuth, HttpTokenExchangeAdapter } from 'isa-auth';
125
+
126
+ const auth = new IsaAuth({ provider: 'github' });
127
+ const exchange = auth.createTokenExchange('/api/auth/token-exchange');
128
+
129
+ // 1. Exchange OAuth code for JWT
130
+ const tokenRes = await exchange.exchangeOAuthCode('github', 'auth-code-123');
131
+ auth.setAccessToken(tokenRes.accessToken);
132
+
133
+ // 2. Exchange World ID ZK-proof for session
134
+ const worldRes = await exchange.exchangeWorldProof(worldProofResult);
135
+ auth.setAccessToken(worldRes.accessToken);
136
+ ```
137
+
138
+ ### Recipe E: Wildcard RBAC / ABAC Guards & Router Redirection
139
+ ```typescript
140
+ import { IsaAuth } from 'isa-auth';
141
+
142
+ const auth = new IsaAuth({ provider: 'jwt' });
143
+
144
+ // Instant wildcard permission check
145
+ const canEdit = auth.can('users:edit'); // Matches 'users:*' or '*'
146
+
147
+ // Navigation Guard for React Router / Vue Router
148
+ const guard = auth.createNavigationGuard({
149
+ requireAuth: true,
150
+ roles: ['ADMIN'],
151
+ roleHierarchy: {
152
+ SUPERUSER: ['ADMIN', 'EDITOR'],
153
+ ADMIN: ['USER'],
154
+ },
155
+ permissions: ['reports:*'],
156
+ redirectToOnUnauthenticated: '/login',
157
+ redirectToOnUnauthorized: '/403',
158
+ onRedirect: (path) => router.push(path),
159
+ });
160
+ ```
161
+
162
+ ### Recipe F: Storage Security & Development Modes
163
+ ```typescript
164
+ import { IsaAuth } from 'isa-auth';
165
+
166
+ // 1. [PRODUCTION DEFAULT] Zero XSS In-Memory Storage (Recommended for SPA)
167
+ const secureAuth = new IsaAuth({
168
+ provider: 'jwt',
169
+ storage: 'memory', // Default! Tokens never touch localStorage.
170
+ });
171
+
172
+ // 2. [PRODUCTION RECOMMENDED] HttpOnly Cookie / BFF Architecture
173
+ const cookieAuth = new IsaAuth({
174
+ provider: 'base',
175
+ storage: 'cookie', // CookieSessionStorageAdapter omits client JWT persistence
176
+ });
177
+
178
+ // 3. [LOCAL DEV ONLY] Insecure LocalStorage for F5 Refresh Convenience
179
+ const devAuth = new IsaAuth({
180
+ provider: 'google',
181
+ clientId: 'dev-client-id',
182
+ storage: 'dev_insecure_localStorage', // Explicitly warns in console that this is NOT for production!
183
+ });
184
+ ```
185
+
186
+ ---
187
+
188
+ ## πŸ› οΈ 3. Monorepo Build & Test Commands
189
+
190
+ ```bash
191
+ # 1. Full Monorepo Build (SWC core compilation + tsup inline bundling)
192
+ yarn build # On Windows: yarn.cmd build
193
+
194
+ # 2. Run Comprehensive Test Suite (22 automated test cases)
195
+ node scratch/test_enhanced_features.js
196
+
197
+ # 3. Launch Local Demo Playground
198
+ yarn demo # Serves http://localhost:3000
199
+ ```
package/README.md CHANGED
@@ -1,25 +1,30 @@
1
1
  # πŸš€ ISA AUTH
2
2
 
3
3
  > **A Unified, Framework-Agnostic Frontend Authentication Suite**
4
- > Supporting Multi-Provider OAuth (Google, Kakao, Naver), Web3 (SIWE), Reactive Store, JWT Management, and RBAC Route Guards.
4
+ > Supporting Multi-Provider OAuth (Google, Apple, Meta, Line, Kakao, Naver), Developer (GitHub, Discord), Web3 (SIWE), Identity (World ID Orb, Passkey WebAuthn), Reactive Store, Axios/Fetch Interceptors, and RBAC/ABAC Guards.
5
5
 
6
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
7
  [![TypeScript](https://img.shields.io/badge/TypeScript-5.8-blue.svg)](https://www.typescriptlang.org/)
8
8
  [![SWC](https://img.shields.io/badge/Compiler-SWC-orange.svg)](https://swc.rs/)
9
+ [![Bundle Size](https://img.shields.io/badge/Zero_Node_Dependencies-Web_Crypto-green.svg)](https://w3c.github.io/webcrypto/)
9
10
 
10
11
  ---
11
12
 
12
13
  ## 🌟 Why ISA AUTH?
13
14
 
14
- Modern web applications frequently require diverse authentication methods β€” from global platforms (Google, Apple) and local providers (Kakao, Naver) to decentralized blockchain identity (SIWE) and standard JWT credentials.
15
+ Modern web applications frequently require diverse authentication methods β€” from global platforms (Google, Apple, Meta) and local portals (Kakao, Naver, Line) to developer communities (GitHub, Discord), decentralized Web3 wallets (SIWE), and next-generation biometric/identity systems (**World ID Orb & Passkey**).
15
16
 
16
17
  **ISA AUTH** provides an all-in-one, frontend-centric architecture that is:
17
18
 
18
19
  - **Framework-Agnostic**: Works seamlessly across Vanilla JS, React, Vue, Svelte, or Web Components.
19
20
  - **Zero Node.js Dependencies**: Pure browser-safe cryptographic & JWT utilities with zero Node runtime bloat.
20
- - **Built-in Reactive State & Persistence**: Lightweight pub/sub store with automatic `localStorage`/`sessionStorage` synchronization across browser tabs.
21
- - **Enterprise-Ready Authorization (RBAC)**: Fine-grained Role and Permission guards for protecting SPA routes and UI elements.
22
- - **Web3 & Modern OAuth Standard**: Native EIP-4361 (Sign-In with Ethereum) and OAuth 2.0 PKCE helpers out-of-the-box.
21
+ - **Categorized Provider Taxonomy**: Organized into `social`, `developer`, `web3`, and `identity` domains.
22
+ - **Next-Gen Identity & Biometrics**: Native support for **World ID (Orb Proof-of-Personhood)** and **Passkey (FIDO2 WebAuthn)**.
23
+ - **Enterprise-Ready RBAC/ABAC**: Wildcard permission matching (`users:*`), role hierarchy inheritance, and router navigation guards.
24
+ - **HTTP Interceptors (Axios & Fetch)**: Auto `Authorization: Bearer <token>` injection and deduplicated 401 refresh queues.
25
+ - **Token Exchange Standard**: Standardized adapter for exchanging OAuth codes, World ID proofs, and Passkey assertions with backend APIs.
26
+ - **Flexible Storage Modes**: Multi-tab synchronization, prefix isolation, and **HttpOnly Cookie / Hybrid BFF mode**.
27
+ - **AI Agent Skill Included**: Embedded `isa-auth-guide` skill directly bundled for agent-assisted development.
23
28
 
24
29
  ---
25
30
 
@@ -35,26 +40,98 @@ pnpm add isa-auth
35
40
 
36
41
  ---
37
42
 
38
- ## πŸš€ Quick Start
43
+ ## πŸ›οΈ Architecture & Provider Taxonomy
39
44
 
40
- ### 1. Unified Authentication Instance
45
+ ```
46
+ [UI Layer] Vanilla DOM / React / Vue / Web Component (<isa-auth-button>)
47
+ β”‚
48
+ [Unified Facade] IsaAuth (packages/isa-auth)
49
+ β”‚
50
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
51
+ β–Ό β–Ό β–Ό β–Ό
52
+ [Providers] [Service] [Store] [Guards & HTTP]
53
+ β”œβ”€ Social - JwtService - Memory - createAuthGuard (RBAC/ABAC)
54
+ β”‚ (Google, Apple,- BaseService - Local - Wildcard & Hierarchy
55
+ β”‚ Meta/FB, - TokenExchange - Session - Navigation Guard
56
+ β”‚ Kakao, Naver,- AutoRefresh - Cookie - onUnauthorized Hook
57
+ β”‚ LINE) - PKCE Utils - Tab Sync - createAuthFetch (Auto 401)
58
+ β”œβ”€ Developer - applyAuthInterceptor (Axios)
59
+ β”‚ (GitHub, Discord)
60
+ β”œβ”€ Web3
61
+ β”‚ (Ethereum SIWE)
62
+ └─ Identity
63
+ (World ID Orb, Passkey FIDO2)
64
+ ```
65
+
66
+ | Category | Providers | Key Features |
67
+ | :--- | :--- | :--- |
68
+ | **`social`** | Google, Apple, Meta/Facebook, Kakao, Naver, LINE | Native SDK wrappers, OpenID Connect, OAuth 2.0 PKCE |
69
+ | **`developer`** | GitHub, Discord | Developer OAuth 2.0 PKCE, Bot/Server authorization |
70
+ | **`web3`** | Ethereum SIWE (EIP-4361) | EIP-1193 wallet detection, `personal_sign` signature |
71
+ | **`identity`** | World ID (Orb), Passkey (WebAuthn/FIDO2) | ZK-SNARK Proof of Personhood, Face ID / Touch ID / Windows Hello |
72
+
73
+ ---
74
+
75
+ ## πŸš€ Quick Start Recipes
76
+
77
+ ### 1. Multi-Provider All-in-One Configuration (Recommended)
78
+
79
+ Manage multiple social logins, developer platforms, and Web3/Passkey authentication simultaneously in a single application instance:
80
+
81
+ ```typescript
82
+ import { IsaAuth } from 'isa-auth';
83
+
84
+ // 1. Initialize with multiple providers at once
85
+ const auth = new IsaAuth({
86
+ storage: 'memory', // Production security default
87
+ providers: {
88
+ google: { clientId: 'GOOGLE_CLIENT_ID', callbackUrl: 'https://myapp.com/callback' },
89
+ kakao: { clientId: 'KAKAO_JAVASCRIPT_KEY', callbackUrl: 'https://myapp.com/callback' },
90
+ apple: { clientId: 'com.myapp.service', callbackUrl: 'https://myapp.com/callback' },
91
+ github: { clientId: 'GITHUB_CLIENT_ID', callbackUrl: 'https://myapp.com/callback' },
92
+ passkey: { rpName: 'My App', rpId: 'myapp.com' },
93
+ },
94
+ });
95
+
96
+ // 2-A. Trigger a specific provider login programmatically
97
+ await auth.signIn('kakao');
98
+ // or
99
+ await auth.signIn('google');
100
+
101
+ // 2-B. Render individual provider button
102
+ auth.renderButton('github', document.getElementById('github-btn-slot'));
103
+
104
+ // 2-C. Render all buttons at once with customizable layout (grid / column / row)
105
+ auth.renderAllButtons(document.getElementById('social-login-container'), {
106
+ direction: 'grid', // 'grid' | 'column' | 'row'
107
+ gap: '12px',
108
+ });
109
+
110
+ // 3. Inspect registered providers
111
+ console.log(auth.getRegisteredProviders()); // ['google', 'kakao', 'apple', 'github', 'passkey']
112
+ ```
113
+
114
+ ---
115
+
116
+ ### 1-B. Single-Provider Configuration (Legacy & Simple Apps)
41
117
 
42
118
  ```typescript
43
119
  import { IsaAuth } from 'isa-auth';
44
120
 
45
- // Initialize with your desired provider
121
+ // Initialize with a single provider
46
122
  const auth = new IsaAuth({
47
- provider: 'google', // 'google' | 'kakao' | 'naver' | 'web3' | 'jwt' | 'base'
48
- clientId: 'YOUR_GOOGLE_CLIENT_ID.apps.googleusercontent.com',
49
- storage: 'localStorage', // 'localStorage' | 'sessionStorage' | 'memory'
123
+ provider: 'google', // 'google' | 'apple' | 'meta' | 'github' | 'discord' | 'web3' | 'world' | 'passkey'
124
+ clientId: 'YOUR_CLIENT_ID',
125
+ callbackUrl: 'https://myapp.com/auth/callback',
126
+ storage: 'memory',
127
+ storagePrefix: 'myapp',
50
128
  });
51
129
 
52
- // Render headless button to a DOM container
130
+ // Render button to a DOM container
53
131
  auth.renderButton(document.getElementById('login-container'));
54
132
 
55
133
  // Listen to authentication changes
56
134
  auth.subscribe((isAuthenticated) => {
57
- console.log('Auth state changed:', isAuthenticated);
58
135
  if (isAuthenticated) {
59
136
  console.log('User Profile:', auth.getUserInfo());
60
137
  console.log('Access Token:', auth.getAccessToken());
@@ -64,96 +141,87 @@ auth.subscribe((isAuthenticated) => {
64
141
 
65
142
  ---
66
143
 
67
- ## πŸ”‘ 5 Core Pillars
144
+ ### 2. 🌐 World ID (World Network / Orb Verification)
68
145
 
69
- ### 1. πŸ“¦ Reactive Store & Multi-Tab Synchronization
70
- Built-in pub/sub store without heavyweight external dependencies. Changes in one tab automatically synchronize across all open browser tabs.
146
+ Verify unique humanness using **World ID Orb** Proof-of-Personhood:
71
147
 
72
148
  ```typescript
73
- import { configureStorage, getAuthState, setAccessToken } from 'isa-auth';
149
+ import { IsaAuth } from 'isa-auth';
74
150
 
75
- // Switch storage adapter
76
- configureStorage('localStorage');
151
+ const worldAuth = new IsaAuth({
152
+ provider: 'world',
153
+ clientId: 'app_staging_your_app_id',
154
+ extraOptions: {
155
+ action: 'vote',
156
+ verificationLevel: 'orb', // 'orb' (Biometric iris scan) or 'device'
157
+ signal: 'user_wallet_address',
158
+ onSuccess: (proof) => {
159
+ console.log('Proof nullifier:', proof.nullifier_hash);
160
+ console.log('ZK-SNARK proof:', proof.proof);
161
+ },
162
+ },
163
+ });
77
164
 
78
- // Set token - automatically parses payload, updates reactive store and syncs across tabs
79
- setAccessToken('eyJhbGciOi...');
165
+ await worldAuth.signIn();
166
+ const user = await worldAuth.getUserInfo();
167
+ console.log(user.isHuman); // true
80
168
  ```
81
169
 
82
- ### 2. πŸ›‘οΈ RBAC & Route Guards
83
- Protect routes and UI components based on JWT claims (`roles` and `permissions`).
170
+ ---
171
+
172
+ ### 3. πŸ”‘ Passkey (FIDO2 / WebAuthn Biometrics)
173
+
174
+ Seamless passwordless authentication via **Face ID, Touch ID, or Windows Hello**:
84
175
 
85
176
  ```typescript
86
- import { createAuthGuard } from 'isa-auth';
177
+ import { IsaAuth } from 'isa-auth';
87
178
 
88
- const adminGuard = createAuthGuard({
89
- requireAuth: true,
90
- roles: ['ADMIN'],
91
- onUnauthorized: () => {
92
- alert('403 Forbidden: Administrator access required.');
93
- },
94
- onUnauthenticated: () => {
95
- window.location.href = '/login';
179
+ const passkeyAuth = new IsaAuth({
180
+ provider: 'passkey',
181
+ extraOptions: {
182
+ rpName: 'My Enterprise Bank',
183
+ userName: 'alice@example.com',
96
184
  },
97
185
  });
98
186
 
99
- // Use inside your router (React Router, Vue Router, etc.)
100
- const canAccess = await adminGuard({
101
- isAuthenticated: auth.isAuthenticated(),
102
- roles: auth.getUserInfo()?.roles,
103
- });
104
- ```
187
+ // Authenticate with device biometrics
188
+ await passkeyAuth.signIn();
105
189
 
106
- ### 3. 🌐 Multi-Provider OAuth (Google, Kakao, Naver)
107
- Standardized provider lifecycle with automatic SDK injection and popup/redirect workflows.
190
+ // Register a new passkey credential
191
+ await passkeyAuth.providerInstance.registerCredential();
192
+ ```
108
193
 
109
- ```typescript
110
- // Kakao Provider
111
- const kakaoAuth = new IsaAuth({
112
- provider: 'kakao',
113
- clientId: 'YOUR_KAKAO_JAVASCRIPT_KEY',
114
- callbackUrl: 'https://your-domain.com/oauth/callback',
115
- });
194
+ ---
116
195
 
117
- // Trigger login
118
- await kakaoAuth.signIn();
119
- ```
196
+ ### 4. πŸ”„ HTTP Interceptors (Axios & Fetch) with 401 Auto-Retry
120
197
 
121
- ### 4. ⛓️ Web3 (Sign-In with Ethereum - SIWE)
122
- Native support for EIP-4361 compliant wallet authentication.
198
+ Automatically attaches `Authorization: Bearer <token>` and queues concurrent requests while refreshing expired tokens:
123
199
 
200
+ #### Axios Interceptor:
124
201
  ```typescript
125
- const web3Auth = new IsaAuth({
126
- provider: 'web3',
127
- extraOptions: {
128
- statement: 'Sign in with Ethereum to access the dashboard.',
129
- chainId: 1,
202
+ import axios from 'axios';
203
+ import { IsaAuth } from 'isa-auth';
204
+
205
+ const auth = new IsaAuth({ provider: 'jwt' });
206
+ const apiClient = axios.create({ baseURL: 'https://api.example.com' });
207
+
208
+ // Applies request/response interceptors to Axios
209
+ auth.applyAxiosInterceptor(apiClient, {
210
+ refreshFn: async () => {
211
+ const res = await axios.post('/api/auth/refresh');
212
+ return res.data.accessToken;
213
+ },
214
+ onUnauthorized: () => {
215
+ window.location.href = '/login';
130
216
  },
131
217
  });
132
218
 
133
- // Prompts MetaMask / browser wallet to connect and sign message
134
- await web3Auth.signIn();
219
+ // All requests now have automatic Bearer token injection and 401 recovery
220
+ const response = await apiClient.get('/users/me');
135
221
  ```
136
222
 
137
- ### 5. πŸ› οΈ Authentication Utilities & Auto-Refresh HTTP Client
138
-
223
+ #### Fetch Interceptor:
139
224
  ```typescript
140
- import {
141
- createAuthFetch,
142
- decodeToken,
143
- isExpiredToken,
144
- generateCodeVerifier,
145
- generateCodeChallenge
146
- } from 'isa-auth';
147
-
148
- // 1. Safe JWT decoding (pure browser)
149
- const { payload } = decodeToken(token);
150
- const expired = isExpiredToken(token);
151
-
152
- // 2. PKCE generators for secure OAuth 2.0
153
- const verifier = generateCodeVerifier();
154
- const challenge = await generateCodeChallenge(verifier);
155
-
156
- // 3. HTTP fetch with auto Bearer token and 401 refresh retry
157
225
  const authFetch = auth.createFetch({
158
226
  baseUrl: 'https://api.example.com',
159
227
  refreshFn: async () => {
@@ -163,75 +231,102 @@ const authFetch = auth.createFetch({
163
231
  },
164
232
  });
165
233
 
166
- // Automatically adds "Authorization: Bearer <token>" and refreshes upon 401
167
- const response = await authFetch('/v1/protected-data');
234
+ const res = await authFetch('/protected/data');
168
235
  ```
169
236
 
170
237
  ---
171
238
 
172
- ## 🎨 Framework Adapters
239
+ ### 5. πŸ›‘οΈ Advanced RBAC/ABAC Guards & Navigation Guards
240
+
241
+ Supports **wildcard permission rules** (`users:*`, `*:read`, `*`) and **hierarchical role inheritance**:
173
242
 
174
- ### Vanilla JavaScript
175
243
  ```typescript
176
- import { renderers } from 'isa-auth';
244
+ import { IsaAuth } from 'isa-auth';
177
245
 
178
- const btn = renderers.renderByJs({
179
- label: 'Google 둜그인',
180
- onClick: () => auth.signIn(),
181
- });
182
- document.body.appendChild(btn);
183
- ```
246
+ const auth = new IsaAuth({ provider: 'jwt' });
184
247
 
185
- ### React
186
- ```tsx
187
- import { renderers } from 'isa-auth';
248
+ // Instant wildcard check
249
+ auth.can('users:read'); // true if user has 'users:*' or '*'
250
+ auth.is('ADMIN'); // role check
251
+
252
+ // Navigation Guard for React Router / Vue Router
253
+ const navGuard = auth.createNavigationGuard({
254
+ requireAuth: true,
255
+ roles: ['ADMIN'],
256
+ roleHierarchy: {
257
+ SUPERUSER: ['ADMIN', 'MANAGER'],
258
+ ADMIN: ['USER'],
259
+ },
260
+ permissions: ['reports:read'],
261
+ redirectToOnUnauthenticated: '/login',
262
+ redirectToOnUnauthorized: '/403',
263
+ onRedirect: (path) => router.push(path),
264
+ });
188
265
 
189
- export function LoginButton() {
190
- return renderers.renderByReact({
191
- label: 'Sign In',
192
- onClick: () => auth.signIn(),
193
- });
266
+ // Use inside router beforeEach hook
267
+ const result = await navGuard();
268
+ if (!result.allowed) {
269
+ console.warn('Denied reason:', result.reason);
194
270
  }
195
271
  ```
196
272
 
197
- ### Web Component
198
- ```html
199
- <script type="module">
200
- import { renderers } from 'isa-auth';
201
- renderers.registerWebComponent();
202
- </script>
273
+ ---
274
+
275
+ ### 6. πŸ”Œ Backend Token Exchange Adapter
276
+
277
+ Standardized bridge for exchanging OAuth authorization codes, World ID proofs, and Passkey assertions with your backend API:
278
+
279
+ ```typescript
280
+ import { IsaAuth } from 'isa-auth';
281
+
282
+ const auth = new IsaAuth({ provider: 'github' });
283
+ const exchange = auth.createTokenExchange('/api/auth/token-exchange');
203
284
 
204
- <isa-auth-button label="Sign In with ISA"></isa-auth-button>
285
+ // 1. Exchange OAuth code for backend JWT
286
+ const tokenRes = await exchange.exchangeOAuthCode('github', 'oauth_code_123');
287
+ auth.setAccessToken(tokenRes.accessToken);
288
+
289
+ // 2. Exchange World ID ZK-Proof for backend session
290
+ const worldRes = await exchange.exchangeWorldProof(worldProof);
291
+ auth.setAccessToken(worldRes.accessToken);
205
292
  ```
206
293
 
207
294
  ---
208
295
 
209
- ## πŸ§ͺ Testing the Playground
296
+ ### 7. πŸ›‘οΈ Storage Modes: Security-First Defaults
210
297
 
211
- Run the interactive local demo to experiment with all features:
298
+ By default, `isa-auth` uses **`'memory'`** storage to ensure sensitive tokens are never exposed to XSS attacks via browser localStorage:
212
299
 
213
- ```bash
214
- # Build packages
215
- yarn build
300
+ ```typescript
301
+ // 1. [PRODUCTION DEFAULT] Zero XSS In-Memory Storage
302
+ const secureAuth = new IsaAuth({
303
+ provider: 'jwt',
304
+ storage: 'memory', // Default! (No tokens in localStorage)
305
+ });
306
+
307
+ // 2. [PRODUCTION RECOMMENDED] HttpOnly Cookie / BFF Mode
308
+ const cookieAuth = new IsaAuth({
309
+ provider: 'base',
310
+ storage: 'cookie', // CookieSessionStorageAdapter (BFF architecture)
311
+ });
216
312
 
217
- # Start interactive playground
218
- yarn demo
219
- # Visit http://localhost:3000 in your browser
313
+ // 3. [LOCAL DEV ONLY] Insecure LocalStorage for F5 Refresh Convenience
314
+ const devAuth = new IsaAuth({
315
+ provider: 'google',
316
+ clientId: 'dev-client-id',
317
+ storage: 'dev_insecure_localStorage', // Explicitly warns in console that this is NOT for production!
318
+ });
220
319
  ```
221
320
 
222
321
  ---
223
322
 
224
- ## πŸ“ Repository Structure
323
+ ## πŸ€– Bundled Agent Skill
225
324
 
226
- ```
227
- isa-auth/
228
- β”œβ”€β”€ packages/
229
- β”‚ β”œβ”€β”€ core/ # @isa-auth/core: JWT, Store, Providers, Guards, HTTP Interceptor
230
- β”‚ β”œβ”€β”€ isa-auth/ # isa-auth: Unified Facade, Multi-Framework Renderers
231
- β”‚ └── demo/ # Interactive Web Playground
232
- β”œβ”€β”€ package.json # Workspace Monorepo
233
- └── README.md
234
- ```
325
+ This package comes pre-packaged with an AI Agent Skill under:
326
+ - `skills/isa-auth-guide/SKILL.md`
327
+ - `.agents/skills/isa-auth-guide/SKILL.md`
328
+
329
+ Supported AI coding agents (Antigravity, Cursor, Windsurf, Claude Code) automatically discover and use this skill for code generation and configuration guidance.
235
330
 
236
331
  ---
237
332