@jezweb/oauth-token-manager 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/README.md +184 -0
- package/SECURITY.md +162 -0
- package/dist/crypto.d.ts +43 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/crypto.js +107 -0
- package/dist/crypto.js.map +1 -0
- package/dist/errors.d.ts +75 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +117 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +54 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +58 -0
- package/dist/index.js.map +1 -0
- package/dist/providers/github.d.ts +45 -0
- package/dist/providers/github.d.ts.map +1 -0
- package/dist/providers/github.js +70 -0
- package/dist/providers/github.js.map +1 -0
- package/dist/providers/google.d.ts +24 -0
- package/dist/providers/google.d.ts.map +1 -0
- package/dist/providers/google.js +63 -0
- package/dist/providers/google.js.map +1 -0
- package/dist/providers/microsoft.d.ts +29 -0
- package/dist/providers/microsoft.d.ts.map +1 -0
- package/dist/providers/microsoft.js +72 -0
- package/dist/providers/microsoft.js.map +1 -0
- package/dist/providers/types.d.ts +7 -0
- package/dist/providers/types.d.ts.map +1 -0
- package/dist/providers/types.js +7 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/storage/d1.d.ts +22 -0
- package/dist/storage/d1.d.ts.map +1 -0
- package/dist/storage/d1.js +31 -0
- package/dist/storage/d1.js.map +1 -0
- package/dist/storage/kv.d.ts +38 -0
- package/dist/storage/kv.d.ts.map +1 -0
- package/dist/storage/kv.js +143 -0
- package/dist/storage/kv.js.map +1 -0
- package/dist/storage/types.d.ts +7 -0
- package/dist/storage/types.d.ts.map +1 -0
- package/dist/storage/types.js +7 -0
- package/dist/storage/types.js.map +1 -0
- package/dist/token-manager.d.ts +88 -0
- package/dist/token-manager.d.ts.map +1 -0
- package/dist/token-manager.js +199 -0
- package/dist/token-manager.js.map +1 -0
- package/dist/types.d.ts +158 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/package.json +88 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core types for OAuth Token Manager
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Stored token data (encrypted at rest)
|
|
6
|
+
*/
|
|
7
|
+
export interface StoredToken {
|
|
8
|
+
/** User identifier from your auth system */
|
|
9
|
+
userId: string;
|
|
10
|
+
/** Provider identifier (e.g., 'google', 'microsoft', 'github') */
|
|
11
|
+
provider: string;
|
|
12
|
+
/** OAuth access token (encrypted) */
|
|
13
|
+
accessToken: string;
|
|
14
|
+
/** OAuth refresh token (encrypted, optional for providers like GitHub) */
|
|
15
|
+
refreshToken?: string;
|
|
16
|
+
/** Token expiration timestamp in milliseconds */
|
|
17
|
+
expiresAt?: number;
|
|
18
|
+
/** Scopes granted by the user */
|
|
19
|
+
scopes: string[];
|
|
20
|
+
/** When the token was first stored */
|
|
21
|
+
createdAt: number;
|
|
22
|
+
/** When the token was last updated */
|
|
23
|
+
updatedAt: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Token data returned to consumers (decrypted)
|
|
27
|
+
*/
|
|
28
|
+
export interface TokenData {
|
|
29
|
+
accessToken: string;
|
|
30
|
+
refreshToken?: string;
|
|
31
|
+
expiresAt?: number;
|
|
32
|
+
scopes: string[];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Options for storing a new token
|
|
36
|
+
*/
|
|
37
|
+
export interface StoreTokenOptions {
|
|
38
|
+
userId: string;
|
|
39
|
+
provider: string;
|
|
40
|
+
accessToken: string;
|
|
41
|
+
refreshToken?: string;
|
|
42
|
+
expiresAt?: number;
|
|
43
|
+
scopes: string[];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Options for retrieving a token
|
|
47
|
+
*/
|
|
48
|
+
export interface GetTokenOptions {
|
|
49
|
+
userId: string;
|
|
50
|
+
provider: string;
|
|
51
|
+
/** If specified, verify these scopes are present */
|
|
52
|
+
requiredScopes?: string[];
|
|
53
|
+
/** Buffer time in ms before expiry to trigger refresh (default: 5 minutes) */
|
|
54
|
+
refreshBuffer?: number;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Options for listing a user's connected providers
|
|
58
|
+
*/
|
|
59
|
+
export interface ListTokensOptions {
|
|
60
|
+
userId: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Summary of a connected provider
|
|
64
|
+
*/
|
|
65
|
+
export interface ConnectedProvider {
|
|
66
|
+
provider: string;
|
|
67
|
+
scopes: string[];
|
|
68
|
+
connectedAt: number;
|
|
69
|
+
expiresAt?: number;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Options for revoking a token
|
|
73
|
+
*/
|
|
74
|
+
export interface RevokeTokenOptions {
|
|
75
|
+
userId: string;
|
|
76
|
+
provider: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Provider configuration for token refresh
|
|
80
|
+
*/
|
|
81
|
+
export interface ProviderConfig {
|
|
82
|
+
clientId: string;
|
|
83
|
+
clientSecret: string;
|
|
84
|
+
/** Microsoft-specific: tenant ID (default: 'common') */
|
|
85
|
+
tenantId?: string;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Token manager configuration
|
|
89
|
+
*/
|
|
90
|
+
export interface TokenManagerConfig {
|
|
91
|
+
/** Storage adapter (KV or D1) */
|
|
92
|
+
storage: TokenStorage;
|
|
93
|
+
/** @deprecated Encryption is handled by the storage adapter. This field is unused. */
|
|
94
|
+
encryptionKey?: string;
|
|
95
|
+
/** Provider configurations for token refresh */
|
|
96
|
+
providers: {
|
|
97
|
+
google?: ProviderConfig;
|
|
98
|
+
microsoft?: ProviderConfig;
|
|
99
|
+
github?: ProviderConfig;
|
|
100
|
+
[key: string]: ProviderConfig | undefined;
|
|
101
|
+
};
|
|
102
|
+
/** Default buffer time before expiry to trigger refresh (default: 5 minutes) */
|
|
103
|
+
defaultRefreshBuffer?: number;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Storage adapter interface
|
|
107
|
+
* Implement this for custom storage backends
|
|
108
|
+
*/
|
|
109
|
+
export interface TokenStorage {
|
|
110
|
+
/**
|
|
111
|
+
* Get a stored token by user and provider
|
|
112
|
+
*/
|
|
113
|
+
get(userId: string, provider: string): Promise<StoredToken | null>;
|
|
114
|
+
/**
|
|
115
|
+
* Store or update a token
|
|
116
|
+
*/
|
|
117
|
+
set(token: StoredToken): Promise<void>;
|
|
118
|
+
/**
|
|
119
|
+
* Delete a token
|
|
120
|
+
*/
|
|
121
|
+
delete(userId: string, provider: string): Promise<void>;
|
|
122
|
+
/**
|
|
123
|
+
* List all providers for a user
|
|
124
|
+
*/
|
|
125
|
+
list(userId: string): Promise<ConnectedProvider[]>;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Provider interface for token refresh
|
|
129
|
+
*/
|
|
130
|
+
export interface TokenProvider {
|
|
131
|
+
/** Provider identifier */
|
|
132
|
+
readonly id: string;
|
|
133
|
+
/**
|
|
134
|
+
* Refresh an expired access token
|
|
135
|
+
* @returns New token data, or null if refresh failed (user needs to re-auth)
|
|
136
|
+
*/
|
|
137
|
+
refresh(refreshToken: string, config: ProviderConfig): Promise<{
|
|
138
|
+
accessToken: string;
|
|
139
|
+
refreshToken?: string;
|
|
140
|
+
expiresAt?: number;
|
|
141
|
+
} | null>;
|
|
142
|
+
/**
|
|
143
|
+
* Whether this provider supports token refresh
|
|
144
|
+
* (GitHub tokens don't expire, so no refresh needed)
|
|
145
|
+
*/
|
|
146
|
+
readonly supportsRefresh: boolean;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Result of a token refresh operation
|
|
150
|
+
*/
|
|
151
|
+
export interface RefreshResult {
|
|
152
|
+
accessToken: string;
|
|
153
|
+
/** New refresh token (some providers rotate) */
|
|
154
|
+
refreshToken?: string;
|
|
155
|
+
/** New expiration time */
|
|
156
|
+
expiresAt?: number;
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,4CAA4C;IAC5C,MAAM,EAAE,MAAM,CAAC;IACf,kEAAkE;IAClE,QAAQ,EAAE,MAAM,CAAC;IACjB,qCAAqC;IACrC,WAAW,EAAE,MAAM,CAAC;IACpB,0EAA0E;IAC1E,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iDAAiD;IACjD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iCAAiC;IACjC,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,sCAAsC;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,sCAAsC;IACtC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,oDAAoD;IACpD,cAAc,CAAC,EAAE,MA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;IAEvC;;OAEG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAExD;;OAEG;IACH,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAAC;CACpD;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,0BAA0B;IAC1B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,OAAO,CACL,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,cAAc,GACrB,OAAO,CAAC;QACT,WAAW,EAAE,MAAM,CAAC;QACpB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,GAAG,IAAI,CAAC,CAAC;IAEV;;;OAGG;IACH,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,gDAAgD;IAChD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,0BAA0B;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
package/package.json
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jezweb/oauth-token-manager",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "OAuth token management for Cloudflare Workers - store, refresh, and retrieve tokens for downstream API access",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./storage/kv": {
|
|
14
|
+
"types": "./dist/storage/kv.d.ts",
|
|
15
|
+
"import": "./dist/storage/kv.js"
|
|
16
|
+
},
|
|
17
|
+
"./storage/d1": {
|
|
18
|
+
"types": "./dist/storage/d1.d.ts",
|
|
19
|
+
"import": "./dist/storage/d1.js"
|
|
20
|
+
},
|
|
21
|
+
"./providers/google": {
|
|
22
|
+
"types": "./dist/providers/google.d.ts",
|
|
23
|
+
"import": "./dist/providers/google.js"
|
|
24
|
+
},
|
|
25
|
+
"./providers/microsoft": {
|
|
26
|
+
"types": "./dist/providers/microsoft.d.ts",
|
|
27
|
+
"import": "./dist/providers/microsoft.js"
|
|
28
|
+
},
|
|
29
|
+
"./providers/github": {
|
|
30
|
+
"types": "./dist/providers/github.d.ts",
|
|
31
|
+
"import": "./dist/providers/github.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist",
|
|
36
|
+
"README.md",
|
|
37
|
+
"SECURITY.md"
|
|
38
|
+
],
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsc",
|
|
41
|
+
"dev": "tsc --watch",
|
|
42
|
+
"test": "vitest run",
|
|
43
|
+
"test:watch": "vitest",
|
|
44
|
+
"lint": "eslint src/",
|
|
45
|
+
"clean": "rm -rf dist",
|
|
46
|
+
"prepublishOnly": "npm run clean && npm run build"
|
|
47
|
+
},
|
|
48
|
+
"keywords": [
|
|
49
|
+
"oauth",
|
|
50
|
+
"token",
|
|
51
|
+
"cloudflare",
|
|
52
|
+
"workers",
|
|
53
|
+
"kv",
|
|
54
|
+
"d1",
|
|
55
|
+
"mcp",
|
|
56
|
+
"api",
|
|
57
|
+
"google",
|
|
58
|
+
"microsoft",
|
|
59
|
+
"github"
|
|
60
|
+
],
|
|
61
|
+
"author": "Jezweb <jeremy@jezweb.net>",
|
|
62
|
+
"license": "MIT",
|
|
63
|
+
"repository": {
|
|
64
|
+
"type": "git",
|
|
65
|
+
"url": "https://github.com/jezweb/oauth-token-manager.git"
|
|
66
|
+
},
|
|
67
|
+
"homepage": "https://github.com/jezweb/oauth-token-manager#readme",
|
|
68
|
+
"bugs": {
|
|
69
|
+
"url": "https://github.com/jezweb/oauth-token-manager/issues"
|
|
70
|
+
},
|
|
71
|
+
"engines": {
|
|
72
|
+
"node": ">=18.0.0"
|
|
73
|
+
},
|
|
74
|
+
"devDependencies": {
|
|
75
|
+
"@cloudflare/workers-types": "^4.20250109.0",
|
|
76
|
+
"@types/node": "^22.10.5",
|
|
77
|
+
"typescript": "^5.7.3",
|
|
78
|
+
"vitest": "^3.0.2"
|
|
79
|
+
},
|
|
80
|
+
"peerDependencies": {
|
|
81
|
+
"@cloudflare/workers-types": ">=4.0.0"
|
|
82
|
+
},
|
|
83
|
+
"peerDependenciesMeta": {
|
|
84
|
+
"@cloudflare/workers-types": {
|
|
85
|
+
"optional": true
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|