@auth-gate/core 0.1.0 → 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.
Files changed (2) hide show
  1. package/README.md +212 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,212 @@
1
+ # @auth-gate/core
2
+
3
+ Core client library for [AuthGate](https://authgate.dev) — the OAuth proxy that handles provider configuration, token exchange, and user normalization so you don't have to.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @auth-gate/core
9
+ ```
10
+
11
+ ## Setup
12
+
13
+ ```ts
14
+ import { createAuthGateClient } from "@auth-gate/core";
15
+
16
+ const client = createAuthGateClient({
17
+ apiKey: process.env.AUTHGATE_API_KEY!,
18
+ projectId: process.env.AUTHGATE_PROJECT_ID!,
19
+ baseUrl: "https://authgate.dev", // or your self-hosted instance
20
+ sessionSecret: process.env.SESSION_SECRET!, // min 32 characters
21
+ });
22
+ ```
23
+
24
+ ## Features
25
+
26
+ ### OAuth Authentication
27
+
28
+ Supports Google, GitHub, Discord, Azure (Microsoft), and Apple.
29
+
30
+ ```ts
31
+ // Generate the authorization URL
32
+ const url = client.getOAuthUrl("google", "https://yourapp.com/auth/callback");
33
+
34
+ // After callback, verify the JWT token from AuthGate
35
+ const result = await client.verifyToken(token);
36
+ if (result.valid) {
37
+ console.log(result.user); // { id, email, name, picture, provider }
38
+ }
39
+ ```
40
+
41
+ ### Session Encryption
42
+
43
+ Sessions are encrypted with AES-256-GCM using keys derived via HKDF-SHA256.
44
+
45
+ ```ts
46
+ // Encrypt a user into a session cookie value
47
+ const cookieValue = await client.encryptSession(user);
48
+
49
+ // Decrypt a session cookie back to a user
50
+ const user = await client.decryptSession(cookieValue);
51
+
52
+ // Get full payload with timestamps
53
+ const payload = await client.decryptSessionPayload(cookieValue);
54
+ // { user, iat, exp }
55
+ ```
56
+
57
+ ### CSRF / OAuth State
58
+
59
+ ```ts
60
+ // Before redirect: create state + nonce
61
+ const { state, nonce } = await client.createState();
62
+ // Store nonce in a cookie, pass state in the OAuth URL
63
+
64
+ // After callback: verify state against nonce
65
+ const valid = await client.verifyState(state, nonce);
66
+ ```
67
+
68
+ ### Email Authentication
69
+
70
+ ```ts
71
+ // Sign up
72
+ await client.emailSignup({ email, password, name });
73
+
74
+ // Sign in
75
+ const result = await client.emailSignin({ email, password });
76
+
77
+ // Verify email with OTP code
78
+ await client.emailVerifyCode({ email, code });
79
+
80
+ // Password reset
81
+ await client.emailForgotPassword({ email });
82
+ await client.emailResetPassword({ token, password });
83
+
84
+ // Magic link
85
+ await client.magicLinkSend({ email, callbackUrl });
86
+ ```
87
+
88
+ ### SMS Authentication
89
+
90
+ ```ts
91
+ // Send verification code
92
+ await client.smsSendCode({ phone }); // E.164 format: +15551234567
93
+
94
+ // Verify code
95
+ const result = await client.smsVerifyCode({ phone, code });
96
+ ```
97
+
98
+ ### Multi-Factor Authentication (MFA)
99
+
100
+ ```ts
101
+ // TOTP setup
102
+ const setup = await client.mfaTotpSetup(jwt);
103
+ // { secret, qr_code, uri }
104
+
105
+ // Verify TOTP setup
106
+ await client.mfaTotpVerifySetup(jwt, { code });
107
+
108
+ // Complete MFA challenge during sign-in
109
+ const result = await client.mfaVerify({ mfa_challenge, code, method: "totp" });
110
+
111
+ // SMS-based MFA
112
+ await client.mfaSmsSendCode({ mfa_challenge });
113
+ await client.mfaVerify({ mfa_challenge, code, method: "sms" });
114
+
115
+ // Backup codes
116
+ const codes = await client.mfaBackupCodesGenerate(jwt);
117
+ ```
118
+
119
+ ### Session Management
120
+
121
+ ```ts
122
+ // Refresh an expired token
123
+ const result = await client.refreshToken(refreshToken);
124
+
125
+ // Revoke a session
126
+ await client.revokeSession(refreshToken);
127
+ ```
128
+
129
+ ### Cookie Helpers
130
+
131
+ ```ts
132
+ client.cookieName; // "__authgate"
133
+ client.nonceCookieName; // "__authgate_nonce"
134
+ client.refreshTokenCookieName; // "__authgate_refresh"
135
+ client.sessionMaxAge; // 604800 (7 days)
136
+
137
+ client.getSessionCookieOptions();
138
+ // { httpOnly: true, secure: true, sameSite: "lax", maxAge: 604800, path: "/" }
139
+
140
+ client.getNonceCookieOptions();
141
+ // { httpOnly: true, secure: true, sameSite: "lax", maxAge: 600, path: "/" }
142
+ ```
143
+
144
+ ## Configuration
145
+
146
+ | Option | Type | Required | Description |
147
+ |--------|------|----------|-------------|
148
+ | `apiKey` | `string` | Yes | Your AuthGate API key |
149
+ | `projectId` | `string` | Yes | Your AuthGate project ID |
150
+ | `baseUrl` | `string` | Yes | AuthGate instance URL |
151
+ | `sessionSecret` | `string` | Yes | Encryption secret (min 32 chars) |
152
+ | `cookieName` | `string` | No | Session cookie name (default: `__authgate`) |
153
+ | `sessionMaxAge` | `number` | No | Session TTL in seconds (default: `604800` / 7 days) |
154
+ | `callbackPath` | `string` | No | OAuth callback path (default: `/api/auth/callback`) |
155
+
156
+ ## Types
157
+
158
+ ```ts
159
+ import type {
160
+ AuthGateUser,
161
+ AuthGateConfig,
162
+ OAuthProvider,
163
+ TokenVerifyResult,
164
+ SessionPayload,
165
+ CookieOptions,
166
+ MfaChallengeResponse,
167
+ MfaStatus,
168
+ TotpSetupResponse,
169
+ BackupCodesResponse,
170
+ } from "@auth-gate/core";
171
+ ```
172
+
173
+ ### `AuthGateUser`
174
+
175
+ ```ts
176
+ interface AuthGateUser {
177
+ id: string;
178
+ email: string;
179
+ phone?: string;
180
+ name?: string;
181
+ picture?: string;
182
+ provider: string;
183
+ }
184
+ ```
185
+
186
+ ### `OAuthProvider`
187
+
188
+ ```ts
189
+ type OAuthProvider = "google" | "github" | "discord" | "azure" | "apple";
190
+ ```
191
+
192
+ ## Error Handling
193
+
194
+ ```ts
195
+ import {
196
+ AuthGateError,
197
+ TokenVerificationError,
198
+ SessionDecryptionError,
199
+ InvalidStateError,
200
+ } from "@auth-gate/core";
201
+ ```
202
+
203
+ ## Framework SDKs
204
+
205
+ For framework-specific integrations with built-in route handlers, session helpers, and middleware:
206
+
207
+ - **Next.js** — [`@auth-gate/nextjs`](https://www.npmjs.com/package/@auth-gate/nextjs)
208
+ - **React + Hono** — [`@auth-gate/react`](https://www.npmjs.com/package/@auth-gate/react)
209
+
210
+ ## License
211
+
212
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auth-gate/core",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {