isa-auth 0.0.0-stage → 0.2.0

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,154 @@
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 A: World ID (World Network / Orb Verification)
29
+ ```typescript
30
+ import { IsaAuth } from 'isa-auth';
31
+
32
+ const worldAuth = new IsaAuth({
33
+ provider: 'world',
34
+ clientId: 'app_staging_your_app_id',
35
+ extraOptions: {
36
+ action: 'vote',
37
+ verificationLevel: 'orb', // 'orb' (Biometric iris scan) or 'device'
38
+ signal: 'user_wallet_0x123',
39
+ onSuccess: (proof) => {
40
+ console.log('ZK Proof generated:', proof.nullifier_hash, proof.proof);
41
+ },
42
+ },
43
+ });
44
+
45
+ await worldAuth.signIn();
46
+ const userInfo = await worldAuth.getUserInfo();
47
+ // { id: '0x...', isHuman: true, verificationLevel: 'orb', ... }
48
+ ```
49
+
50
+ ### Recipe B: Passkey (FIDO2 / WebAuthn Biometrics)
51
+ ```typescript
52
+ import { IsaAuth } from 'isa-auth';
53
+
54
+ const passkeyAuth = new IsaAuth({
55
+ provider: 'passkey',
56
+ extraOptions: {
57
+ rpName: 'My Financial App',
58
+ rpId: window.location.hostname,
59
+ userName: 'alice@example.com',
60
+ },
61
+ });
62
+
63
+ // Authenticate via Face ID / Touch ID / Windows Hello
64
+ await passkeyAuth.signIn();
65
+
66
+ // Register new biometric credential
67
+ await passkeyAuth.providerInstance.registerCredential();
68
+ ```
69
+
70
+ ### Recipe C: Axios Interceptor with Automatic 401 Refresh & Queue
71
+ ```typescript
72
+ import axios from 'axios';
73
+ import { IsaAuth } from 'isa-auth';
74
+
75
+ const auth = new IsaAuth({ provider: 'jwt' });
76
+ const apiClient = axios.create({ baseURL: 'https://api.example.com' });
77
+
78
+ // Applies Authorization: Bearer <token> & deduplicated 401 token refresh queue
79
+ auth.applyAxiosInterceptor(apiClient, {
80
+ refreshFn: async () => {
81
+ const res = await axios.post('/api/auth/refresh');
82
+ return res.data.accessToken;
83
+ },
84
+ onUnauthorized: () => {
85
+ window.location.href = '/login';
86
+ },
87
+ });
88
+ ```
89
+
90
+ ### Recipe D: Backend Token Exchange Adapter
91
+ ```typescript
92
+ import { IsaAuth, HttpTokenExchangeAdapter } from 'isa-auth';
93
+
94
+ const auth = new IsaAuth({ provider: 'github' });
95
+ const exchange = auth.createTokenExchange('/api/auth/token-exchange');
96
+
97
+ // 1. Exchange OAuth code for JWT
98
+ const tokenRes = await exchange.exchangeOAuthCode('github', 'auth-code-123');
99
+ auth.setAccessToken(tokenRes.accessToken);
100
+
101
+ // 2. Exchange World ID ZK-proof for session
102
+ const worldRes = await exchange.exchangeWorldProof(worldProofResult);
103
+ auth.setAccessToken(worldRes.accessToken);
104
+ ```
105
+
106
+ ### Recipe E: Wildcard RBAC / ABAC Guards & Router Redirection
107
+ ```typescript
108
+ import { IsaAuth } from 'isa-auth';
109
+
110
+ const auth = new IsaAuth({ provider: 'jwt' });
111
+
112
+ // Instant wildcard permission check
113
+ const canEdit = auth.can('users:edit'); // Matches 'users:*' or '*'
114
+
115
+ // Navigation Guard for React Router / Vue Router
116
+ const guard = auth.createNavigationGuard({
117
+ requireAuth: true,
118
+ roles: ['ADMIN'],
119
+ roleHierarchy: {
120
+ SUPERUSER: ['ADMIN', 'EDITOR'],
121
+ ADMIN: ['USER'],
122
+ },
123
+ permissions: ['reports:*'],
124
+ redirectToOnUnauthenticated: '/login',
125
+ redirectToOnUnauthorized: '/403',
126
+ onRedirect: (path) => router.push(path),
127
+ });
128
+ ```
129
+
130
+ ### Recipe F: HttpOnly Cookie / Hybrid Session Storage
131
+ ```typescript
132
+ import { IsaAuth } from 'isa-auth';
133
+
134
+ // In BFF setups where tokens live exclusively in HttpOnly cookies:
135
+ const auth = new IsaAuth({
136
+ provider: 'base',
137
+ storage: 'cookie', // CookieSessionStorageAdapter omits client JWT persistence
138
+ });
139
+ ```
140
+
141
+ ---
142
+
143
+ ## 🛠️ 3. Monorepo Build & Test Commands
144
+
145
+ ```bash
146
+ # 1. Full Monorepo Build (SWC core compilation + tsup inline bundling)
147
+ yarn build # On Windows: yarn.cmd build
148
+
149
+ # 2. Run Comprehensive Test Suite (22 automated test cases)
150
+ node scratch/test_enhanced_features.js
151
+
152
+ # 3. Launch Local Demo Playground
153
+ yarn demo # Serves http://localhost:3000
154
+ ```
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 ISA
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,296 @@
1
- # Temporary Holding Version
1
+ # 🚀 ISA AUTH
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ > **A Unified, Framework-Agnostic Frontend Authentication Suite**
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
+
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.8-blue.svg)](https://www.typescriptlang.org/)
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/)
10
+
11
+ ---
12
+
13
+ ## 🌟 Why ISA AUTH?
14
+
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**).
16
+
17
+ **ISA AUTH** provides an all-in-one, frontend-centric architecture that is:
18
+
19
+ - **Framework-Agnostic**: Works seamlessly across Vanilla JS, React, Vue, Svelte, or Web Components.
20
+ - **Zero Node.js Dependencies**: Pure browser-safe cryptographic & JWT utilities with zero Node runtime bloat.
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.
28
+
29
+ ---
30
+
31
+ ## 📦 Installation
32
+
33
+ ```bash
34
+ npm install isa-auth
35
+ # or
36
+ yarn add isa-auth
37
+ # or
38
+ pnpm add isa-auth
39
+ ```
40
+
41
+ ---
42
+
43
+ ## 🏛️ Architecture & Provider Taxonomy
44
+
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. Unified Authentication Instance
78
+
79
+ ```typescript
80
+ import { IsaAuth } from 'isa-auth';
81
+
82
+ // Initialize with any provider
83
+ const auth = new IsaAuth({
84
+ provider: 'google', // 'google' | 'apple' | 'meta' | 'github' | 'discord' | 'web3' | 'world' | 'passkey'
85
+ clientId: 'YOUR_CLIENT_ID',
86
+ callbackUrl: 'https://myapp.com/auth/callback',
87
+ storage: 'localStorage', // 'localStorage' | 'sessionStorage' | 'memory' | 'cookie'
88
+ storagePrefix: 'myapp',
89
+ });
90
+
91
+ // Render headless button to a DOM container
92
+ auth.renderButton(document.getElementById('login-container'));
93
+
94
+ // Listen to authentication changes
95
+ auth.subscribe((isAuthenticated) => {
96
+ if (isAuthenticated) {
97
+ console.log('User Profile:', auth.getUserInfo());
98
+ console.log('Access Token:', auth.getAccessToken());
99
+ }
100
+ });
101
+ ```
102
+
103
+ ---
104
+
105
+ ### 2. 🌐 World ID (World Network / Orb Verification)
106
+
107
+ Verify unique humanness using **World ID Orb** Proof-of-Personhood:
108
+
109
+ ```typescript
110
+ import { IsaAuth } from 'isa-auth';
111
+
112
+ const worldAuth = new IsaAuth({
113
+ provider: 'world',
114
+ clientId: 'app_staging_your_app_id',
115
+ extraOptions: {
116
+ action: 'vote',
117
+ verificationLevel: 'orb', // 'orb' (Biometric iris scan) or 'device'
118
+ signal: 'user_wallet_address',
119
+ onSuccess: (proof) => {
120
+ console.log('Proof nullifier:', proof.nullifier_hash);
121
+ console.log('ZK-SNARK proof:', proof.proof);
122
+ },
123
+ },
124
+ });
125
+
126
+ await worldAuth.signIn();
127
+ const user = await worldAuth.getUserInfo();
128
+ console.log(user.isHuman); // true
129
+ ```
130
+
131
+ ---
132
+
133
+ ### 3. 🔑 Passkey (FIDO2 / WebAuthn Biometrics)
134
+
135
+ Seamless passwordless authentication via **Face ID, Touch ID, or Windows Hello**:
136
+
137
+ ```typescript
138
+ import { IsaAuth } from 'isa-auth';
139
+
140
+ const passkeyAuth = new IsaAuth({
141
+ provider: 'passkey',
142
+ extraOptions: {
143
+ rpName: 'My Enterprise Bank',
144
+ userName: 'alice@example.com',
145
+ },
146
+ });
147
+
148
+ // Authenticate with device biometrics
149
+ await passkeyAuth.signIn();
150
+
151
+ // Register a new passkey credential
152
+ await passkeyAuth.providerInstance.registerCredential();
153
+ ```
154
+
155
+ ---
156
+
157
+ ### 4. 🔄 HTTP Interceptors (Axios & Fetch) with 401 Auto-Retry
158
+
159
+ Automatically attaches `Authorization: Bearer <token>` and queues concurrent requests while refreshing expired tokens:
160
+
161
+ #### Axios Interceptor:
162
+ ```typescript
163
+ import axios from 'axios';
164
+ import { IsaAuth } from 'isa-auth';
165
+
166
+ const auth = new IsaAuth({ provider: 'jwt' });
167
+ const apiClient = axios.create({ baseURL: 'https://api.example.com' });
168
+
169
+ // Applies request/response interceptors to Axios
170
+ auth.applyAxiosInterceptor(apiClient, {
171
+ refreshFn: async () => {
172
+ const res = await axios.post('/api/auth/refresh');
173
+ return res.data.accessToken;
174
+ },
175
+ onUnauthorized: () => {
176
+ window.location.href = '/login';
177
+ },
178
+ });
179
+
180
+ // All requests now have automatic Bearer token injection and 401 recovery
181
+ const response = await apiClient.get('/users/me');
182
+ ```
183
+
184
+ #### Fetch Interceptor:
185
+ ```typescript
186
+ const authFetch = auth.createFetch({
187
+ baseUrl: 'https://api.example.com',
188
+ refreshFn: async () => {
189
+ const res = await fetch('/api/auth/refresh', { method: 'POST' });
190
+ const data = await res.json();
191
+ return data.accessToken;
192
+ },
193
+ });
194
+
195
+ const res = await authFetch('/protected/data');
196
+ ```
197
+
198
+ ---
199
+
200
+ ### 5. 🛡️ Advanced RBAC/ABAC Guards & Navigation Guards
201
+
202
+ Supports **wildcard permission rules** (`users:*`, `*:read`, `*`) and **hierarchical role inheritance**:
203
+
204
+ ```typescript
205
+ import { IsaAuth } from 'isa-auth';
206
+
207
+ const auth = new IsaAuth({ provider: 'jwt' });
208
+
209
+ // Instant wildcard check
210
+ auth.can('users:read'); // true if user has 'users:*' or '*'
211
+ auth.is('ADMIN'); // role check
212
+
213
+ // Navigation Guard for React Router / Vue Router
214
+ const navGuard = auth.createNavigationGuard({
215
+ requireAuth: true,
216
+ roles: ['ADMIN'],
217
+ roleHierarchy: {
218
+ SUPERUSER: ['ADMIN', 'MANAGER'],
219
+ ADMIN: ['USER'],
220
+ },
221
+ permissions: ['reports:read'],
222
+ redirectToOnUnauthenticated: '/login',
223
+ redirectToOnUnauthorized: '/403',
224
+ onRedirect: (path) => router.push(path),
225
+ });
226
+
227
+ // Use inside router beforeEach hook
228
+ const result = await navGuard();
229
+ if (!result.allowed) {
230
+ console.warn('Denied reason:', result.reason);
231
+ }
232
+ ```
233
+
234
+ ---
235
+
236
+ ### 6. 🔌 Backend Token Exchange Adapter
237
+
238
+ Standardized bridge for exchanging OAuth authorization codes, World ID proofs, and Passkey assertions with your backend API:
239
+
240
+ ```typescript
241
+ import { IsaAuth } from 'isa-auth';
242
+
243
+ const auth = new IsaAuth({ provider: 'github' });
244
+ const exchange = auth.createTokenExchange('/api/auth/token-exchange');
245
+
246
+ // 1. Exchange OAuth code for backend JWT
247
+ const tokenRes = await exchange.exchangeOAuthCode('github', 'oauth_code_123');
248
+ auth.setAccessToken(tokenRes.accessToken);
249
+
250
+ // 2. Exchange World ID ZK-Proof for backend session
251
+ const worldRes = await exchange.exchangeWorldProof(worldProof);
252
+ auth.setAccessToken(worldRes.accessToken);
253
+ ```
254
+
255
+ ---
256
+
257
+ ### 7. 🛡️ Storage Modes: Security-First Defaults
258
+
259
+ By default, `isa-auth` uses **`'memory'`** storage to ensure sensitive tokens are never exposed to XSS attacks via browser localStorage:
260
+
261
+ ```typescript
262
+ // 1. [PRODUCTION DEFAULT] Zero XSS In-Memory Storage
263
+ const secureAuth = new IsaAuth({
264
+ provider: 'jwt',
265
+ storage: 'memory', // Default! (No tokens in localStorage)
266
+ });
267
+
268
+ // 2. [PRODUCTION RECOMMENDED] HttpOnly Cookie / BFF Mode
269
+ const cookieAuth = new IsaAuth({
270
+ provider: 'base',
271
+ storage: 'cookie', // CookieSessionStorageAdapter (BFF architecture)
272
+ });
273
+
274
+ // 3. [LOCAL DEV ONLY] Insecure LocalStorage for F5 Refresh Convenience
275
+ const devAuth = new IsaAuth({
276
+ provider: 'google',
277
+ clientId: 'dev-client-id',
278
+ storage: 'dev_insecure_localStorage', // Explicitly warns in console that this is NOT for production!
279
+ });
280
+ ```
281
+
282
+ ---
283
+
284
+ ## 🤖 Bundled Agent Skill
285
+
286
+ This package comes pre-packaged with an AI Agent Skill under:
287
+ - `skills/isa-auth-guide/SKILL.md`
288
+ - `.agents/skills/isa-auth-guide/SKILL.md`
289
+
290
+ Supported AI coding agents (Antigravity, Cursor, Windsurf, Claude Code) automatically discover and use this skill for code generation and configuration guidance.
291
+
292
+ ---
293
+
294
+ ## 📄 License
295
+
296
+ This project is licensed under the [MIT License](./LICENSE).