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.
- package/.agents/skills/isa-auth-guide/SKILL.md +199 -0
- package/README.md +217 -122
- package/dist/index.d.mts +814 -72
- package/dist/index.d.ts +814 -72
- package/dist/index.js +2531 -350
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2530 -349
- package/dist/index.mjs.map +1 -1
- package/package.json +23 -6
- package/skills/isa-auth-guide/SKILL.md +199 -0
|
@@ -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,
|
|
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
|
[](https://opensource.org/licenses/MIT)
|
|
7
7
|
[](https://www.typescriptlang.org/)
|
|
8
8
|
[](https://swc.rs/)
|
|
9
|
+
[](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
|
|
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
|
-
- **
|
|
21
|
-
- **
|
|
22
|
-
- **
|
|
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
|
-
##
|
|
43
|
+
## ποΈ Architecture & Provider Taxonomy
|
|
39
44
|
|
|
40
|
-
|
|
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
|
|
121
|
+
// Initialize with a single provider
|
|
46
122
|
const auth = new IsaAuth({
|
|
47
|
-
provider: 'google', // 'google' | '
|
|
48
|
-
clientId: '
|
|
49
|
-
|
|
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
|
|
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
|
-
|
|
144
|
+
### 2. π World ID (World Network / Orb Verification)
|
|
68
145
|
|
|
69
|
-
|
|
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 {
|
|
149
|
+
import { IsaAuth } from 'isa-auth';
|
|
74
150
|
|
|
75
|
-
|
|
76
|
-
|
|
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
|
-
|
|
79
|
-
|
|
165
|
+
await worldAuth.signIn();
|
|
166
|
+
const user = await worldAuth.getUserInfo();
|
|
167
|
+
console.log(user.isHuman); // true
|
|
80
168
|
```
|
|
81
169
|
|
|
82
|
-
|
|
83
|
-
|
|
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 {
|
|
177
|
+
import { IsaAuth } from 'isa-auth';
|
|
87
178
|
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
-
//
|
|
100
|
-
|
|
101
|
-
isAuthenticated: auth.isAuthenticated(),
|
|
102
|
-
roles: auth.getUserInfo()?.roles,
|
|
103
|
-
});
|
|
104
|
-
```
|
|
187
|
+
// Authenticate with device biometrics
|
|
188
|
+
await passkeyAuth.signIn();
|
|
105
189
|
|
|
106
|
-
|
|
107
|
-
|
|
190
|
+
// Register a new passkey credential
|
|
191
|
+
await passkeyAuth.providerInstance.registerCredential();
|
|
192
|
+
```
|
|
108
193
|
|
|
109
|
-
|
|
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
|
-
|
|
118
|
-
await kakaoAuth.signIn();
|
|
119
|
-
```
|
|
196
|
+
### 4. π HTTP Interceptors (Axios & Fetch) with 401 Auto-Retry
|
|
120
197
|
|
|
121
|
-
|
|
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
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
-
//
|
|
134
|
-
await
|
|
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
|
-
|
|
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
|
-
|
|
167
|
-
const response = await authFetch('/v1/protected-data');
|
|
234
|
+
const res = await authFetch('/protected/data');
|
|
168
235
|
```
|
|
169
236
|
|
|
170
237
|
---
|
|
171
238
|
|
|
172
|
-
|
|
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 {
|
|
244
|
+
import { IsaAuth } from 'isa-auth';
|
|
177
245
|
|
|
178
|
-
const
|
|
179
|
-
label: 'Google λ‘κ·ΈμΈ',
|
|
180
|
-
onClick: () => auth.signIn(),
|
|
181
|
-
});
|
|
182
|
-
document.body.appendChild(btn);
|
|
183
|
-
```
|
|
246
|
+
const auth = new IsaAuth({ provider: 'jwt' });
|
|
184
247
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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
|
-
|
|
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
|
-
|
|
296
|
+
### 7. π‘οΈ Storage Modes: Security-First Defaults
|
|
210
297
|
|
|
211
|
-
|
|
298
|
+
By default, `isa-auth` uses **`'memory'`** storage to ensure sensitive tokens are never exposed to XSS attacks via browser localStorage:
|
|
212
299
|
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
|
|
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
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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
|
-
##
|
|
323
|
+
## π€ Bundled Agent Skill
|
|
225
324
|
|
|
226
|
-
|
|
227
|
-
isa-auth/
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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
|
|