@dainprotocol/oauth2-token-manager 0.3.0 → 0.3.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.
Files changed (2) hide show
  1. package/README.md +68 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -11,6 +11,7 @@ A simple OAuth2 token management library for Node.js. Store and manage OAuth2 to
11
11
  - [API Reference](#-api-reference)
12
12
  - [Storage Adapters](#-storage-adapters)
13
13
  - [Examples](#-examples)
14
+ - [Security](#-security)
14
15
 
15
16
  ## 🚀 Features
16
17
 
@@ -20,6 +21,7 @@ A simple OAuth2 token management library for Node.js. Store and manage OAuth2 to
20
21
  - **Profile Fetching**: Get user profiles during OAuth callback
21
22
  - **Custom Profile Fetchers**: Register custom profile fetchers per storage instance
22
23
  - **Pluggable Storage**: In-memory, PostgreSQL, Drizzle, or custom adapters
24
+ - **Token Encryption**: AES-256-CBC encryption for tokens at rest (CASA compliant)
23
25
  - **Type Safe**: Full TypeScript support
24
26
 
25
27
  ## 📦 Installation
@@ -93,6 +95,7 @@ const accessToken = await oauth.getAccessToken('google', 'user@example.com');
93
95
  2. **Automatic override**: Saving a token with same provider + email replaces the old one
94
96
  3. **Auto refresh**: Expired tokens refresh automatically when you request them
95
97
  4. **Simple storage**: Just provider (string), userId (string), and email (string)
98
+ 5. **Encrypted tokens**: Access and refresh tokens are encrypted at rest using AES-256-CBC
96
99
 
97
100
  ## 📚 API Reference
98
101
 
@@ -502,6 +505,49 @@ const accessToken = await oauth.getAccessToken('customApi', 'user@example.com');
502
505
 
503
506
  See [Custom Token Paths Guide](./CUSTOM_TOKEN_PATHS.md) for more examples.
504
507
 
508
+ ### Token Encryption
509
+
510
+ All storage adapters support AES-256-CBC encryption for tokens at rest:
511
+
512
+ ```typescript
513
+ // In-Memory with encryption
514
+ import { InMemoryStorageAdapter } from '@dainprotocol/oauth2-token-manager';
515
+
516
+ const storage = new InMemoryStorageAdapter({
517
+ encryptionKey: process.env.TOKEN_ENCRYPTION_KEY, // Min 32 characters
518
+ });
519
+
520
+ // PostgreSQL with encryption
521
+ import { PostgresStorageFactory } from '@dainprotocol/oauth2-storage-postgres';
522
+
523
+ const storage = await PostgresStorageFactory.create({
524
+ host: 'localhost',
525
+ port: 5432,
526
+ username: 'user',
527
+ password: 'password',
528
+ database: 'oauth_tokens',
529
+ encryption: {
530
+ encryptionKey: process.env.TOKEN_ENCRYPTION_KEY,
531
+ },
532
+ });
533
+
534
+ // Drizzle with encryption
535
+ import { DrizzleStorageAdapter } from '@dainprotocol/oauth2-storage-drizzle';
536
+
537
+ const storage = await DrizzleStorageAdapter.create(db, {
538
+ dialect: 'postgres',
539
+ encryption: {
540
+ encryptionKey: process.env.TOKEN_ENCRYPTION_KEY,
541
+ },
542
+ });
543
+ ```
544
+
545
+ Generate a secure encryption key:
546
+
547
+ ```bash
548
+ openssl rand -base64 32
549
+ ```
550
+
505
551
  ### Custom Profile Fetcher Example
506
552
 
507
553
  ```typescript
@@ -562,6 +608,28 @@ const testStorage = await DrizzleStorageAdapter.create(testDb, {
562
608
  });
563
609
  ```
564
610
 
611
+ ## 🔒 Security
612
+
613
+ ### Encryption Specification
614
+
615
+ | Specification | Implementation |
616
+ | -------------- | -------------- |
617
+ | Algorithm | AES-256-CBC |
618
+ | Key Derivation | PBKDF2 |
619
+ | Integrity | HMAC signature |
620
+ | Min Key Length | 32 characters |
621
+
622
+ ### What Gets Encrypted
623
+
624
+ - `accessToken` - Always encrypted
625
+ - `refreshToken` - Always encrypted (when present)
626
+
627
+ ### CASA Compliance
628
+
629
+ This library meets Google CASA (Cloud Application Security Assessment) requirements for token storage. For CASA submissions:
630
+
631
+ > OAuth tokens (access_token, refresh_token) are encrypted at rest using AES-256-CBC symmetric encryption with PBKDF2 key derivation via the iron-session library, which includes HMAC integrity verification.
632
+
565
633
  ## 📄 License
566
634
 
567
635
  MIT © Dain Protocol
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dainprotocol/oauth2-token-manager",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "A scalable OAuth2 token management library with multi-system support",
5
5
  "keywords": [
6
6
  "oauth2",