isa-auth 0.0.0-stage β†’ 0.1.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.
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,240 @@
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, Kakao, Naver), Web3 (SIWE), Reactive Store, JWT Management, and RBAC Route 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
+
10
+ ---
11
+
12
+ ## 🌟 Why ISA AUTH?
13
+
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
+
16
+ **ISA AUTH** provides an all-in-one, frontend-centric architecture that is:
17
+
18
+ - **Framework-Agnostic**: Works seamlessly across Vanilla JS, React, Vue, Svelte, or Web Components.
19
+ - **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.
23
+
24
+ ---
25
+
26
+ ## πŸ“¦ Installation
27
+
28
+ ```bash
29
+ npm install isa-auth
30
+ # or
31
+ yarn add isa-auth
32
+ # or
33
+ pnpm add isa-auth
34
+ ```
35
+
36
+ ---
37
+
38
+ ## πŸš€ Quick Start
39
+
40
+ ### 1. Unified Authentication Instance
41
+
42
+ ```typescript
43
+ import { IsaAuth } from 'isa-auth';
44
+
45
+ // Initialize with your desired provider
46
+ 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'
50
+ });
51
+
52
+ // Render headless button to a DOM container
53
+ auth.renderButton(document.getElementById('login-container'));
54
+
55
+ // Listen to authentication changes
56
+ auth.subscribe((isAuthenticated) => {
57
+ console.log('Auth state changed:', isAuthenticated);
58
+ if (isAuthenticated) {
59
+ console.log('User Profile:', auth.getUserInfo());
60
+ console.log('Access Token:', auth.getAccessToken());
61
+ }
62
+ });
63
+ ```
64
+
65
+ ---
66
+
67
+ ## πŸ”‘ 5 Core Pillars
68
+
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.
71
+
72
+ ```typescript
73
+ import { configureStorage, getAuthState, setAccessToken } from 'isa-auth';
74
+
75
+ // Switch storage adapter
76
+ configureStorage('localStorage');
77
+
78
+ // Set token - automatically parses payload, updates reactive store and syncs across tabs
79
+ setAccessToken('eyJhbGciOi...');
80
+ ```
81
+
82
+ ### 2. πŸ›‘οΈ RBAC & Route Guards
83
+ Protect routes and UI components based on JWT claims (`roles` and `permissions`).
84
+
85
+ ```typescript
86
+ import { createAuthGuard } from 'isa-auth';
87
+
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';
96
+ },
97
+ });
98
+
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
+ ```
105
+
106
+ ### 3. 🌐 Multi-Provider OAuth (Google, Kakao, Naver)
107
+ Standardized provider lifecycle with automatic SDK injection and popup/redirect workflows.
108
+
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
+ });
116
+
117
+ // Trigger login
118
+ await kakaoAuth.signIn();
119
+ ```
120
+
121
+ ### 4. ⛓️ Web3 (Sign-In with Ethereum - SIWE)
122
+ Native support for EIP-4361 compliant wallet authentication.
123
+
124
+ ```typescript
125
+ const web3Auth = new IsaAuth({
126
+ provider: 'web3',
127
+ extraOptions: {
128
+ statement: 'Sign in with Ethereum to access the dashboard.',
129
+ chainId: 1,
130
+ },
131
+ });
132
+
133
+ // Prompts MetaMask / browser wallet to connect and sign message
134
+ await web3Auth.signIn();
135
+ ```
136
+
137
+ ### 5. πŸ› οΈ Authentication Utilities & Auto-Refresh HTTP Client
138
+
139
+ ```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
+ const authFetch = auth.createFetch({
158
+ baseUrl: 'https://api.example.com',
159
+ refreshFn: async () => {
160
+ const res = await fetch('/api/auth/refresh', { method: 'POST' });
161
+ const data = await res.json();
162
+ return data.accessToken;
163
+ },
164
+ });
165
+
166
+ // Automatically adds "Authorization: Bearer <token>" and refreshes upon 401
167
+ const response = await authFetch('/v1/protected-data');
168
+ ```
169
+
170
+ ---
171
+
172
+ ## 🎨 Framework Adapters
173
+
174
+ ### Vanilla JavaScript
175
+ ```typescript
176
+ import { renderers } from 'isa-auth';
177
+
178
+ const btn = renderers.renderByJs({
179
+ label: 'Google 둜그인',
180
+ onClick: () => auth.signIn(),
181
+ });
182
+ document.body.appendChild(btn);
183
+ ```
184
+
185
+ ### React
186
+ ```tsx
187
+ import { renderers } from 'isa-auth';
188
+
189
+ export function LoginButton() {
190
+ return renderers.renderByReact({
191
+ label: 'Sign In',
192
+ onClick: () => auth.signIn(),
193
+ });
194
+ }
195
+ ```
196
+
197
+ ### Web Component
198
+ ```html
199
+ <script type="module">
200
+ import { renderers } from 'isa-auth';
201
+ renderers.registerWebComponent();
202
+ </script>
203
+
204
+ <isa-auth-button label="Sign In with ISA"></isa-auth-button>
205
+ ```
206
+
207
+ ---
208
+
209
+ ## πŸ§ͺ Testing the Playground
210
+
211
+ Run the interactive local demo to experiment with all features:
212
+
213
+ ```bash
214
+ # Build packages
215
+ yarn build
216
+
217
+ # Start interactive playground
218
+ yarn demo
219
+ # Visit http://localhost:3000 in your browser
220
+ ```
221
+
222
+ ---
223
+
224
+ ## πŸ“ Repository Structure
225
+
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
+ ```
235
+
236
+ ---
237
+
238
+ ## πŸ“„ License
239
+
240
+ This project is licensed under the [MIT License](./LICENSE).