@hawcx/oauth-client 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 +22 -0
- package/README.md +304 -0
- package/dist/client.d.ts +134 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +301 -0
- package/dist/client.js.map +1 -0
- package/dist/delegation/client.d.ts +116 -0
- package/dist/delegation/client.d.ts.map +1 -0
- package/dist/delegation/client.js +227 -0
- package/dist/delegation/client.js.map +1 -0
- package/dist/delegation/crypto.d.ts +72 -0
- package/dist/delegation/crypto.d.ts.map +1 -0
- package/dist/delegation/crypto.js +356 -0
- package/dist/delegation/crypto.js.map +1 -0
- package/dist/delegation/exceptions.d.ts +32 -0
- package/dist/delegation/exceptions.d.ts.map +1 -0
- package/dist/delegation/exceptions.js +61 -0
- package/dist/delegation/exceptions.js.map +1 -0
- package/dist/delegation/hawcx.d.ts +254 -0
- package/dist/delegation/hawcx.d.ts.map +1 -0
- package/dist/delegation/hawcx.js +326 -0
- package/dist/delegation/hawcx.js.map +1 -0
- package/dist/delegation/index.d.ts +14 -0
- package/dist/delegation/index.d.ts.map +1 -0
- package/dist/delegation/index.js +30 -0
- package/dist/delegation/index.js.map +1 -0
- package/dist/exceptions.d.ts +52 -0
- package/dist/exceptions.d.ts.map +1 -0
- package/dist/exceptions.js +81 -0
- package/dist/exceptions.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +55 -0
- package/dist/index.js.map +1 -0
- package/dist/utils.d.ts +61 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +263 -0
- package/dist/utils.js.map +1 -0
- package/package.json +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Hawcx
|
|
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.
|
|
22
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
# Hawcx OAuth Client SDK (Node.js)
|
|
2
|
+
|
|
3
|
+
A lightweight, production-ready Node.js/TypeScript library for exchanging OAuth authorization codes and verifying JWT claims. Built with security, reliability, and ease of use in mind.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- ๐ **Secure JWT Verification**: RS256/ES256/EdDSA signature verification with configurable validation
|
|
8
|
+
- ๐ **PKCE Support**: Native PKCE (RFC 7636) support for enhanced OAuth security
|
|
9
|
+
- ๐ **Simple API**: One function call to go from code to verified claims
|
|
10
|
+
- ๐ฏ **High-Level Hawcx Client**: One-line MFA setup with automatic encryption/signing
|
|
11
|
+
- ๐ก๏ธ **Comprehensive Error Handling**: Clear, actionable error messages for all failure scenarios
|
|
12
|
+
- ๐ **TypeScript First**: Full type definitions for better IDE support and type checking
|
|
13
|
+
- ๐งช **Production Ready**: Extensive error handling and security best practices
|
|
14
|
+
- ๐ง **Express/Fastify Compatible**: Works with any Node.js framework
|
|
15
|
+
- ๐ **Detailed Logging**: Structured logging for debugging (no sensitive data logged)
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @hawcx/oauth-client
|
|
21
|
+
|
|
22
|
+
# or with yarn
|
|
23
|
+
yarn add @hawcx/oauth-client
|
|
24
|
+
|
|
25
|
+
# or with pnpm
|
|
26
|
+
pnpm add @hawcx/oauth-client
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Quick Start
|
|
30
|
+
|
|
31
|
+
### OAuth Code Exchange
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { exchangeCodeForClaims } from '@hawcx/oauth-client';
|
|
35
|
+
|
|
36
|
+
// Exchange authorization code for verified claims
|
|
37
|
+
const claims = await exchangeCodeForClaims({
|
|
38
|
+
code: req.body.code,
|
|
39
|
+
oauthTokenUrl: process.env.OAUTH_TOKEN_ENDPOINT!,
|
|
40
|
+
clientId: process.env.OAUTH_CLIENT_ID!,
|
|
41
|
+
publicKey: process.env.OAUTH_PUBLIC_KEY!,
|
|
42
|
+
// Optional (recommended for production):
|
|
43
|
+
codeVerifier: session.pkceVerifier, // PKCE support
|
|
44
|
+
audience: 'my-app', // Validate 'aud' claim
|
|
45
|
+
issuer: 'https://oauth.example.com', // Validate 'iss' claim
|
|
46
|
+
leeway: 10 // Clock skew tolerance
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// Use the verified claims
|
|
50
|
+
const userId = claims.sub;
|
|
51
|
+
// Mint your own access token (SDK only verifies, doesn't mint)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Hawcx Delegation (MFA Setup)
|
|
55
|
+
|
|
56
|
+
For Hawcx MFA setup and user management, use the delegation client:
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import { HawcxDelegationClient, MfaMethod } from '@hawcx/oauth-client';
|
|
60
|
+
|
|
61
|
+
// ๐ One-line initialization from explicit keys!
|
|
62
|
+
const client = HawcxDelegationClient.fromKeys({
|
|
63
|
+
spSigningKey: process.env.SP_ED25519_PRIVATE_KEY_PEM!,
|
|
64
|
+
spEncryptionKey: process.env.SP_X25519_PRIVATE_KEY_PEM!,
|
|
65
|
+
idpVerifyKey: process.env.IDP_ED25519_PUBLIC_KEY_PEM!,
|
|
66
|
+
idpEncryptionKey: process.env.IDP_X25519_PUBLIC_KEY_PEM!,
|
|
67
|
+
baseUrl: 'https://ceasar-api.hawcx.com',
|
|
68
|
+
spId: process.env.OAUTH_CLIENT_ID!
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// Initiate MFA setup (Email, SMS, or TOTP)
|
|
72
|
+
const result = await client.initiateMfaChange({
|
|
73
|
+
userid: "user@example.com",
|
|
74
|
+
mfaMethod: MfaMethod.SMS,
|
|
75
|
+
phoneNumber: "+15551234567"
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Verify OTP and complete MFA setup
|
|
79
|
+
await client.verifyMfaChange({
|
|
80
|
+
userid: "user@example.com",
|
|
81
|
+
sessionId: result.session_id,
|
|
82
|
+
otp: "123456"
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// Get user credentials
|
|
86
|
+
const creds = await client.getUserCredentials("user@example.com");
|
|
87
|
+
console.log(`MFA method: ${creds.mfa_method}`);
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**What it does automatically**: ECIES encryption, Ed25519 signatures, request/response crypto, Hawcx payload formatting, type-safe `MfaMethod` enum
|
|
91
|
+
|
|
92
|
+
## Demo App
|
|
93
|
+
|
|
94
|
+
A simple demo application is included to show the OAuth and delegation flows in action:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
cd demo
|
|
98
|
+
cp env.template .env
|
|
99
|
+
# Edit .env with your credentials
|
|
100
|
+
npm install
|
|
101
|
+
npm run dev
|
|
102
|
+
# Visit http://localhost:3000
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
See [demo/README.md](demo/README.md) for details.
|
|
106
|
+
|
|
107
|
+
## Configuration
|
|
108
|
+
|
|
109
|
+
### Environment Variables
|
|
110
|
+
|
|
111
|
+
**For OAuth Code Exchange:**
|
|
112
|
+
```bash
|
|
113
|
+
OAUTH_TOKEN_ENDPOINT="https://oauth.example.com/token"
|
|
114
|
+
OAUTH_CLIENT_ID="your-client-id"
|
|
115
|
+
OAUTH_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----\n..."
|
|
116
|
+
OAUTH_ISSUER="https://oauth.example.com" # Optional but recommended
|
|
117
|
+
OAUTH_AUDIENCE="your-client-id" # Optional but recommended
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
**For Hawcx Delegation:**
|
|
121
|
+
```bash
|
|
122
|
+
SP_ED25519_PRIVATE_KEY_PEM="-----BEGIN PRIVATE KEY-----..."
|
|
123
|
+
SP_X25519_PRIVATE_KEY_PEM="-----BEGIN PRIVATE KEY-----..."
|
|
124
|
+
IDP_ED25519_PUBLIC_KEY_PEM="-----BEGIN PUBLIC KEY-----..."
|
|
125
|
+
IDP_X25519_PUBLIC_KEY_PEM="-----BEGIN PUBLIC KEY-----..."
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Public Key Formats
|
|
129
|
+
|
|
130
|
+
The SDK accepts public keys in multiple formats:
|
|
131
|
+
|
|
132
|
+
**From file:**
|
|
133
|
+
```typescript
|
|
134
|
+
const claims = await exchangeCodeForClaims({
|
|
135
|
+
// ...
|
|
136
|
+
publicKey: '/path/to/public.pem' // Absolute path
|
|
137
|
+
});
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
**From environment variable:**
|
|
141
|
+
```typescript
|
|
142
|
+
const claims = await exchangeCodeForClaims({
|
|
143
|
+
// ...
|
|
144
|
+
publicKey: process.env.OAUTH_PUBLIC_KEY! // PEM string
|
|
145
|
+
});
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
**Expected PEM format:**
|
|
149
|
+
```
|
|
150
|
+
-----BEGIN PUBLIC KEY-----
|
|
151
|
+
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA...
|
|
152
|
+
-----END PUBLIC KEY-----
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Error Handling
|
|
156
|
+
|
|
157
|
+
The SDK provides specific exceptions for different failure scenarios:
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
import {
|
|
161
|
+
exchangeCodeForClaims,
|
|
162
|
+
OAuthExchangeError,
|
|
163
|
+
JWTVerificationError,
|
|
164
|
+
InvalidPublicKeyError
|
|
165
|
+
} from '@hawcx/oauth-client';
|
|
166
|
+
|
|
167
|
+
try {
|
|
168
|
+
const claims = await exchangeCodeForClaims({
|
|
169
|
+
code,
|
|
170
|
+
oauthTokenUrl,
|
|
171
|
+
clientId,
|
|
172
|
+
publicKey
|
|
173
|
+
});
|
|
174
|
+
} catch (error) {
|
|
175
|
+
if (error instanceof OAuthExchangeError) {
|
|
176
|
+
// Code exchange failed (invalid code, network error, etc.)
|
|
177
|
+
console.error(`Exchange failed: ${error.message}`);
|
|
178
|
+
console.error(`HTTP Status: ${error.statusCode}`);
|
|
179
|
+
console.error(`Response: ${error.responseBody}`);
|
|
180
|
+
} else if (error instanceof JWTVerificationError) {
|
|
181
|
+
// JWT verification failed (invalid signature, expired, etc.)
|
|
182
|
+
console.error(`Verification failed: ${error.message}`);
|
|
183
|
+
console.error(`Original error: ${error.originalError}`);
|
|
184
|
+
} else if (error instanceof InvalidPublicKeyError) {
|
|
185
|
+
// Public key is invalid or unreadable
|
|
186
|
+
console.error(`Key error: ${error.message}`);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Common Error Scenarios
|
|
192
|
+
|
|
193
|
+
| Exception | Common Causes | Recommended Action |
|
|
194
|
+
|-----------|--------------|-------------------|
|
|
195
|
+
| `OAuthExchangeError` | Invalid/expired code, network issues | Ask user to re-authenticate |
|
|
196
|
+
| `JWTVerificationError` | Token tampering, expired token | Log incident, ask user to re-authenticate |
|
|
197
|
+
| `InvalidPublicKeyError` | Wrong key, file not found | Check configuration, verify key format |
|
|
198
|
+
|
|
199
|
+
## Security Best Practices
|
|
200
|
+
|
|
201
|
+
### โ
DO
|
|
202
|
+
|
|
203
|
+
- **Always validate audience and issuer** in production environments
|
|
204
|
+
- **Use HTTPS** for all OAuth endpoints
|
|
205
|
+
- **Store keys securely** (environment variables, secrets manager)
|
|
206
|
+
- **Set appropriate leeway** for clock skew (5-10 seconds typical)
|
|
207
|
+
- **Log authentication failures** for security monitoring
|
|
208
|
+
- **Rotate keys regularly** following your security policy
|
|
209
|
+
|
|
210
|
+
### โ DON'T
|
|
211
|
+
|
|
212
|
+
- **Never log JWT tokens** or claims containing sensitive data
|
|
213
|
+
- **Don't disable signature verification** in production
|
|
214
|
+
- **Don't use the id_token as your application's access token** (mint your own)
|
|
215
|
+
- **Don't commit keys** to version control
|
|
216
|
+
- **Don't ignore verification errors** or catch them silently
|
|
217
|
+
|
|
218
|
+
## API Reference
|
|
219
|
+
|
|
220
|
+
### `exchangeCodeForClaims()`
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
async function exchangeCodeForClaims(
|
|
224
|
+
options: ExchangeCodeOptions
|
|
225
|
+
): Promise<Record<string, any>>
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
**Parameters:**
|
|
229
|
+
- `code` (string): Authorization code from OAuth flow
|
|
230
|
+
- `oauthTokenUrl` (string): Token endpoint URL
|
|
231
|
+
- `clientId` (string): OAuth client identifier
|
|
232
|
+
- `publicKey` (string): RS256 public key (PEM string or file path)
|
|
233
|
+
- `codeVerifier` (string, optional): PKCE code verifier (RFC 7636)
|
|
234
|
+
- `redirectUri` (string, optional): OAuth redirect URI
|
|
235
|
+
- `timeout` (number, optional): Request timeout in seconds (default: 20)
|
|
236
|
+
- `audience` (string, optional): Expected 'aud' claim (recommended)
|
|
237
|
+
- `issuer` (string, optional): Expected 'iss' claim (recommended)
|
|
238
|
+
- `verifyExp` (boolean, optional): Verify token expiration (default: true)
|
|
239
|
+
- `leeway` (number, optional): Clock skew tolerance in seconds (default: 0)
|
|
240
|
+
- `algorithms` (string[], optional): Allowed signing algorithms (default: RS256, ES256/384/512, EdDSA)
|
|
241
|
+
|
|
242
|
+
**Returns:** `Promise<Record<string, any>>` - Verified JWT claims
|
|
243
|
+
|
|
244
|
+
**Throws:**
|
|
245
|
+
- `OAuthExchangeError`: Code exchange failed
|
|
246
|
+
- `JWTVerificationError`: JWT verification failed
|
|
247
|
+
- `InvalidPublicKeyError`: Public key invalid
|
|
248
|
+
|
|
249
|
+
### `verifyJwt()`
|
|
250
|
+
|
|
251
|
+
```typescript
|
|
252
|
+
function verifyJwt(
|
|
253
|
+
options: VerifyJwtOptions
|
|
254
|
+
): Record<string, any>
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
Verify a JWT and return its claims. See full documentation in [API.md](./API.md).
|
|
258
|
+
|
|
259
|
+
### HawcxDelegationClient
|
|
260
|
+
|
|
261
|
+
See [DELEGATION.md](./DELEGATION.md) for full Hawcx delegation client documentation.
|
|
262
|
+
|
|
263
|
+
## TypeScript Support
|
|
264
|
+
|
|
265
|
+
This package is written in TypeScript and includes full type definitions:
|
|
266
|
+
|
|
267
|
+
```typescript
|
|
268
|
+
import type {
|
|
269
|
+
ExchangeCodeOptions,
|
|
270
|
+
VerifyJwtOptions
|
|
271
|
+
} from '@hawcx/oauth-client';
|
|
272
|
+
|
|
273
|
+
// All options are fully typed
|
|
274
|
+
const options: ExchangeCodeOptions = {
|
|
275
|
+
code: 'abc123',
|
|
276
|
+
oauthTokenUrl: 'https://oauth.example.com/token',
|
|
277
|
+
clientId: 'my-app',
|
|
278
|
+
publicKey: process.env.OAUTH_PUBLIC_KEY!,
|
|
279
|
+
audience: 'my-app', // TypeScript will catch typos!
|
|
280
|
+
};
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
## Development
|
|
284
|
+
|
|
285
|
+
### Building
|
|
286
|
+
|
|
287
|
+
```bash
|
|
288
|
+
npm install
|
|
289
|
+
npm run build
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
### Testing
|
|
293
|
+
|
|
294
|
+
```bash
|
|
295
|
+
npm test
|
|
296
|
+
npm run test:coverage
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### Linting
|
|
300
|
+
|
|
301
|
+
```bash
|
|
302
|
+
npm run lint
|
|
303
|
+
npm run format
|
|
304
|
+
```
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core OAuth client implementation
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Options for exchanging authorization code for claims
|
|
6
|
+
*/
|
|
7
|
+
export interface ExchangeCodeOptions {
|
|
8
|
+
/** Authorization code from OAuth flow */
|
|
9
|
+
code: string;
|
|
10
|
+
/** Token endpoint URL */
|
|
11
|
+
oauthTokenUrl: string;
|
|
12
|
+
/** OAuth client identifier */
|
|
13
|
+
clientId: string;
|
|
14
|
+
/** Ed25519 public key (PEM string or file path) - optional if jwksUrl provided */
|
|
15
|
+
publicKey?: string;
|
|
16
|
+
/** JWKS URL for dynamic key fetching (alternative to publicKey) */
|
|
17
|
+
jwksUrl?: string;
|
|
18
|
+
/** API key for OAuth provider (required for Hawcx) */
|
|
19
|
+
apiKey?: string;
|
|
20
|
+
/** PKCE code verifier (optional, recommended for security) */
|
|
21
|
+
codeVerifier?: string;
|
|
22
|
+
/** OAuth redirect URI (optional, required by some providers) */
|
|
23
|
+
redirectUri?: string;
|
|
24
|
+
/** Request timeout in seconds (default: 20) */
|
|
25
|
+
timeout?: number;
|
|
26
|
+
/** Expected 'aud' claim (optional but recommended) */
|
|
27
|
+
audience?: string;
|
|
28
|
+
/** Expected 'iss' claim (optional but recommended) */
|
|
29
|
+
issuer?: string;
|
|
30
|
+
/** Verify token expiration (default: true) */
|
|
31
|
+
verifyExp?: boolean;
|
|
32
|
+
/** Clock skew tolerance in seconds (default: 0) */
|
|
33
|
+
leeway?: number;
|
|
34
|
+
/** List of allowed signing algorithms (default: RS256, ES256/384/512, EdDSA) */
|
|
35
|
+
algorithms?: string[];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Options for verifying JWT tokens
|
|
39
|
+
*/
|
|
40
|
+
export interface VerifyJwtOptions {
|
|
41
|
+
/** JWT token to verify */
|
|
42
|
+
token: string;
|
|
43
|
+
/** Public key for JWT verification (PEM string or file path) - optional if jwksUrl provided */
|
|
44
|
+
publicKey?: string;
|
|
45
|
+
/** JWKS URL for dynamic key fetching (alternative to publicKey) */
|
|
46
|
+
jwksUrl?: string;
|
|
47
|
+
/** Expected 'aud' claim (optional but recommended) */
|
|
48
|
+
audience?: string;
|
|
49
|
+
/** Expected 'iss' claim (optional but recommended) */
|
|
50
|
+
issuer?: string;
|
|
51
|
+
/** Verify token expiration (default: true) */
|
|
52
|
+
verifyExp?: boolean;
|
|
53
|
+
/** Clock skew tolerance in seconds (default: 0) */
|
|
54
|
+
leeway?: number;
|
|
55
|
+
/** List of allowed signing algorithms (default: RS256, ES256/384/512, EdDSA) */
|
|
56
|
+
algorithms?: string[];
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Exchange OAuth authorization code for verified JWT claims.
|
|
60
|
+
*
|
|
61
|
+
* Supports PKCE (Proof Key for Code Exchange) per RFC 7636 for enhanced security.
|
|
62
|
+
*
|
|
63
|
+
* @param options - Configuration options for code exchange
|
|
64
|
+
* @returns Dictionary containing the verified JWT claims
|
|
65
|
+
* @throws OAuthExchangeError - Code exchange failed
|
|
66
|
+
* @throws JWTVerificationError - JWT verification failed
|
|
67
|
+
* @throws InvalidPublicKeyError - Public key invalid
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* // Basic usage
|
|
72
|
+
* const claims = await exchangeCodeForClaims({
|
|
73
|
+
* code: req.body.code,
|
|
74
|
+
* oauthTokenUrl: 'https://oauth.example.com/token',
|
|
75
|
+
* clientId: 'my-app',
|
|
76
|
+
* publicKey: '/path/to/public.pem'
|
|
77
|
+
* });
|
|
78
|
+
*
|
|
79
|
+
* // With PKCE (recommended)
|
|
80
|
+
* const claims = await exchangeCodeForClaims({
|
|
81
|
+
* code: req.body.code,
|
|
82
|
+
* oauthTokenUrl: 'https://oauth.example.com/token',
|
|
83
|
+
* clientId: 'my-app',
|
|
84
|
+
* publicKey: process.env.OAUTH_PUBLIC_KEY!,
|
|
85
|
+
* codeVerifier: session.pkceVerifier,
|
|
86
|
+
* redirectUri: 'https://myapp.com/callback',
|
|
87
|
+
* audience: 'my-app',
|
|
88
|
+
* issuer: 'https://oauth.example.com'
|
|
89
|
+
* });
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export declare function exchangeCodeForClaims(options: ExchangeCodeOptions): Promise<Record<string, any>>;
|
|
93
|
+
/**
|
|
94
|
+
* Exchange OAuth authorization code for verified JWT claims and the raw id_token.
|
|
95
|
+
*
|
|
96
|
+
* @param options - Configuration options for code exchange
|
|
97
|
+
* @returns Tuple containing [claims, idToken]
|
|
98
|
+
* @throws OAuthExchangeError - Code exchange failed
|
|
99
|
+
* @throws JWTVerificationError - JWT verification failed
|
|
100
|
+
* @throws InvalidPublicKeyError - Public key invalid
|
|
101
|
+
*/
|
|
102
|
+
export declare function exchangeCodeForTokenAndClaims(options: ExchangeCodeOptions): Promise<[Record<string, any>, string]>;
|
|
103
|
+
/**
|
|
104
|
+
* Verify a JWT and return its claims.
|
|
105
|
+
*
|
|
106
|
+
* This function verifies the JWT signature using the provided public key
|
|
107
|
+
* and validates claims (audience, issuer, expiration).
|
|
108
|
+
*
|
|
109
|
+
* @param options - Configuration options for JWT verification
|
|
110
|
+
* @returns Dictionary containing the verified JWT claims
|
|
111
|
+
* @throws JWTVerificationError - JWT verification failed
|
|
112
|
+
* @throws InvalidPublicKeyError - Public key invalid
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* // Basic usage
|
|
117
|
+
* const claims = verifyJwt({
|
|
118
|
+
* token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9...',
|
|
119
|
+
* publicKey: 'keys/public.pem'
|
|
120
|
+
* });
|
|
121
|
+
* console.log(`User: ${claims.sub}`);
|
|
122
|
+
*
|
|
123
|
+
* // With validation
|
|
124
|
+
* const claims = verifyJwt({
|
|
125
|
+
* token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9...',
|
|
126
|
+
* publicKey: process.env.OAUTH_PUBLIC_KEY!,
|
|
127
|
+
* audience: 'my-app',
|
|
128
|
+
* issuer: 'https://oauth.example.com',
|
|
129
|
+
* leeway: 10 // Allow 10 seconds clock skew
|
|
130
|
+
* });
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
export declare function verifyJwt(options: VerifyJwtOptions): Promise<Record<string, any>>;
|
|
134
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAWH;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,yBAAyB;IACzB,aAAa,EAAE,MAAM,CAAC;IACtB,8BAA8B;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,kFAAkF;IAClF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mEAAmE;IACnE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sDAAsD;IACtD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,8DAA8D;IAC9D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gEAAgE;IAChE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,+CAA+C;IAC/C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sDAAsD;IACtD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sDAAsD;IACtD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,8CAA8C;IAC9C,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,mDAAmD;IACnD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gFAAgF;IAChF,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,0BAA0B;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,+FAA+F;IAC/F,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mEAAmE;IACnE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sDAAsD;IACtD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sDAAsD;IACtD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,8CAA8C;IAC9C,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,mDAAmD;IACnD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gFAAgF;IAChF,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB;AAoED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAgE9B;AAED;;;;;;;;GAQG;AACH,wBAAsB,6BAA6B,CACjD,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC,CAiDxC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAsB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAyHvF"}
|