@geekmidas/auth 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.
- package/dist/{cacheTokenStorage-Ca05vf3T.mjs → cacheTokenStorage-16NE8Cd9.mjs} +3 -3
- package/dist/cacheTokenStorage-16NE8Cd9.mjs.map +1 -0
- package/dist/{cacheTokenStorage-BzBRJfd-.d.mts → cacheTokenStorage-B7sOoysu.d.cts} +8 -6
- package/dist/cacheTokenStorage-B7sOoysu.d.cts.map +1 -0
- package/dist/{cacheTokenStorage-CvptztkW.cjs → cacheTokenStorage-CEpMniTi.cjs} +3 -3
- package/dist/cacheTokenStorage-CEpMniTi.cjs.map +1 -0
- package/dist/{cacheTokenStorage-yNUpDD8W.d.cts → cacheTokenStorage-_tq4Kmhc.d.mts} +8 -6
- package/dist/cacheTokenStorage-_tq4Kmhc.d.mts.map +1 -0
- package/dist/cacheTokenStorage.cjs +1 -1
- package/dist/cacheTokenStorage.d.cts +1 -1
- package/dist/cacheTokenStorage.d.mts +1 -1
- package/dist/cacheTokenStorage.mjs +1 -1
- package/dist/{client-DaiUm0UZ.cjs → client-BPl_mMvb.cjs} +14 -8
- package/dist/client-BPl_mMvb.cjs.map +1 -0
- package/dist/{client-DjNZS6vZ.mjs → client-eidYNJSH.mjs} +14 -8
- package/dist/client-eidYNJSH.mjs.map +1 -0
- package/dist/client.cjs +2 -2
- package/dist/client.d.cts +1 -1
- package/dist/client.d.mts +1 -1
- package/dist/client.mjs +2 -2
- package/dist/hono/jwt.cjs +1 -1
- package/dist/hono/jwt.cjs.map +1 -1
- package/dist/hono/jwt.d.cts +2 -1
- package/dist/hono/jwt.d.cts.map +1 -0
- package/dist/hono/jwt.d.mts +2 -1
- package/dist/hono/jwt.d.mts.map +1 -0
- package/dist/hono/jwt.mjs +1 -1
- package/dist/hono/jwt.mjs.map +1 -1
- package/dist/hono/oidc.cjs +1 -1
- package/dist/hono/oidc.cjs.map +1 -1
- package/dist/hono/oidc.d.cts +3 -2
- package/dist/hono/oidc.d.cts.map +1 -0
- package/dist/hono/oidc.d.mts +3 -2
- package/dist/hono/oidc.d.mts.map +1 -0
- package/dist/hono/oidc.mjs +1 -1
- package/dist/hono/oidc.mjs.map +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +3 -3
- package/dist/{jwt-DF9kFbmh.d.cts → jwt-3eIuY2dg.d.cts} +2 -1
- package/dist/jwt-3eIuY2dg.d.cts.map +1 -0
- package/dist/jwt-Bo_eACEi.cjs.map +1 -1
- package/dist/{jwt-DH8CJ2xC.d.mts → jwt-BqLlRkw-.d.mts} +2 -1
- package/dist/jwt-BqLlRkw-.d.mts.map +1 -0
- package/dist/jwt-D88cPJyT.mjs.map +1 -1
- package/dist/jwt.d.cts +1 -1
- package/dist/jwt.d.mts +1 -1
- package/dist/lambda/jwt.cjs +2 -2
- package/dist/lambda/jwt.cjs.map +1 -1
- package/dist/lambda/jwt.d.cts +2 -1
- package/dist/lambda/jwt.d.cts.map +1 -0
- package/dist/lambda/jwt.d.mts +2 -1
- package/dist/lambda/jwt.d.mts.map +1 -0
- package/dist/lambda/jwt.mjs +2 -2
- package/dist/lambda/jwt.mjs.map +1 -1
- package/dist/lambda/oidc.cjs +2 -2
- package/dist/lambda/oidc.cjs.map +1 -1
- package/dist/lambda/oidc.d.cts +3 -2
- package/dist/lambda/oidc.d.cts.map +1 -0
- package/dist/lambda/oidc.d.mts +3 -2
- package/dist/lambda/oidc.d.mts.map +1 -0
- package/dist/lambda/oidc.mjs +2 -2
- package/dist/lambda/oidc.mjs.map +1 -1
- package/dist/oidc-C0KyYaAK.cjs.map +1 -1
- package/dist/{oidc-CKOGLxjV.d.mts → oidc-ChA17wLB.d.cts} +3 -2
- package/dist/oidc-ChA17wLB.d.cts.map +1 -0
- package/dist/{oidc-DDLIB5gb.d.cts → oidc-DTRgBBl6.d.mts} +3 -2
- package/dist/oidc-DTRgBBl6.d.mts.map +1 -0
- package/dist/oidc-KA30gMlx.mjs.map +1 -1
- package/dist/oidc.d.cts +2 -2
- package/dist/oidc.d.mts +2 -2
- package/dist/server.cjs +2 -2
- package/dist/server.d.cts +2 -2
- package/dist/server.d.mts +2 -2
- package/dist/server.mjs +2 -2
- package/dist/{tokenManager--Q93eNYr.d.mts → tokenManager-CL3yE06D.d.cts} +2 -1
- package/dist/tokenManager-CL3yE06D.d.cts.map +1 -0
- package/dist/{tokenManager-BVXxfHRa.mjs → tokenManager-Ci2Tgxp8.mjs} +5 -3
- package/dist/tokenManager-Ci2Tgxp8.mjs.map +1 -0
- package/dist/{tokenManager-EPmwgai2.cjs → tokenManager-CvEMgxOp.cjs} +5 -3
- package/dist/tokenManager-CvEMgxOp.cjs.map +1 -0
- package/dist/{tokenManager-H6-lWEah.d.cts → tokenManager-RrwjL0y-.d.mts} +2 -1
- package/dist/tokenManager-RrwjL0y-.d.mts.map +1 -0
- package/dist/tokenManager.cjs +1 -1
- package/dist/tokenManager.d.cts +1 -1
- package/dist/tokenManager.d.mts +1 -1
- package/dist/tokenManager.mjs +1 -1
- package/package.json +3 -3
- package/src/__tests__/cacheTokenStorage.spec.ts +148 -148
- package/src/__tests__/client.spec.ts +339 -339
- package/src/__tests__/hono-jwt.spec.ts +219 -219
- package/src/__tests__/hono-oidc.spec.ts +560 -560
- package/src/__tests__/jwt.spec.ts +150 -127
- package/src/__tests__/lambda-jwt.spec.ts +205 -205
- package/src/__tests__/lambda-oidc.spec.ts +580 -579
- package/src/__tests__/oidc.spec.ts +365 -365
- package/src/__tests__/tokenManager.spec.ts +254 -254
- package/src/cacheTokenStorage.ts +32 -32
- package/src/client.ts +199 -190
- package/src/hono/jwt.ts +111 -111
- package/src/hono/oidc.ts +131 -131
- package/src/index.ts +2 -2
- package/src/jwt.ts +57 -57
- package/src/lambda/jwt.ts +170 -170
- package/src/lambda/oidc.ts +165 -165
- package/src/oidc.ts +121 -121
- package/src/server.ts +6 -7
- package/src/tokenManager.ts +89 -87
- package/tsconfig.json +10 -0
- package/dist/cacheTokenStorage-Ca05vf3T.mjs.map +0 -1
- package/dist/cacheTokenStorage-CvptztkW.cjs.map +0 -1
- package/dist/client-DaiUm0UZ.cjs.map +0 -1
- package/dist/client-DjNZS6vZ.mjs.map +0 -1
- package/dist/tokenManager-BVXxfHRa.mjs.map +0 -1
- package/dist/tokenManager-EPmwgai2.cjs.map +0 -1
|
@@ -4,210 +4,210 @@ import { beforeEach, describe, expect, it } from 'vitest';
|
|
|
4
4
|
import { CacheTokenStorage } from '../cacheTokenStorage.ts';
|
|
5
5
|
|
|
6
6
|
describe('CacheTokenStorage', () => {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
let storage: CacheTokenStorage;
|
|
8
|
+
let cache: Cache<string>;
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
cache = new InMemoryCache<string>();
|
|
12
|
+
storage = new CacheTokenStorage(cache);
|
|
13
|
+
});
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
describe('access token operations', () => {
|
|
16
|
+
it('should store and retrieve access token', async () => {
|
|
17
|
+
await storage.setAccessToken('test-access-token');
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
const token = await storage.getAccessToken();
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
expect(token).toBe('test-access-token');
|
|
22
|
+
});
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
it('should return null when no access token exists', async () => {
|
|
25
|
+
const token = await storage.getAccessToken();
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
expect(token).toBeNull();
|
|
28
|
+
});
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
it('should store access token with TTL', async () => {
|
|
31
|
+
await storage.setAccessToken('test-access-token', 3600);
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
const token = await storage.getAccessToken();
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
expect(token).toBe('test-access-token');
|
|
36
|
+
});
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
it('should overwrite existing access token', async () => {
|
|
39
|
+
await storage.setAccessToken('first-token');
|
|
40
|
+
await storage.setAccessToken('second-token');
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
const token = await storage.getAccessToken();
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
expect(token).toBe('second-token');
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
describe('refresh token operations', () => {
|
|
49
|
+
it('should store and retrieve refresh token', async () => {
|
|
50
|
+
await storage.setRefreshToken('test-refresh-token');
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
const token = await storage.getRefreshToken();
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
expect(token).toBe('test-refresh-token');
|
|
55
|
+
});
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
it('should return null when no refresh token exists', async () => {
|
|
58
|
+
const token = await storage.getRefreshToken();
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
expect(token).toBeNull();
|
|
61
|
+
});
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
it('should store refresh token with TTL', async () => {
|
|
64
|
+
await storage.setRefreshToken('test-refresh-token', 7200);
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
const token = await storage.getRefreshToken();
|
|
67
67
|
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
expect(token).toBe('test-refresh-token');
|
|
69
|
+
});
|
|
70
70
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
it('should overwrite existing refresh token', async () => {
|
|
72
|
+
await storage.setRefreshToken('first-refresh-token');
|
|
73
|
+
await storage.setRefreshToken('second-refresh-token');
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
const token = await storage.getRefreshToken();
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
expect(token).toBe('second-refresh-token');
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
80
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
describe('token lifecycle', () => {
|
|
82
|
+
it('should store both tokens independently', async () => {
|
|
83
|
+
await storage.setAccessToken('access-token');
|
|
84
|
+
await storage.setRefreshToken('refresh-token');
|
|
85
85
|
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
const accessToken = await storage.getAccessToken();
|
|
87
|
+
const refreshToken = await storage.getRefreshToken();
|
|
88
88
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
89
|
+
expect(accessToken).toBe('access-token');
|
|
90
|
+
expect(refreshToken).toBe('refresh-token');
|
|
91
|
+
});
|
|
92
92
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
it('should clear both tokens', async () => {
|
|
94
|
+
await storage.setAccessToken('access-token');
|
|
95
|
+
await storage.setRefreshToken('refresh-token');
|
|
96
96
|
|
|
97
|
-
|
|
97
|
+
await storage.clearTokens();
|
|
98
98
|
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
const accessToken = await storage.getAccessToken();
|
|
100
|
+
const refreshToken = await storage.getRefreshToken();
|
|
101
101
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
102
|
+
expect(accessToken).toBeNull();
|
|
103
|
+
expect(refreshToken).toBeNull();
|
|
104
|
+
});
|
|
105
105
|
|
|
106
|
-
|
|
107
|
-
|
|
106
|
+
it('should clear tokens when some are missing', async () => {
|
|
107
|
+
await storage.setAccessToken('access-token');
|
|
108
108
|
|
|
109
|
-
|
|
109
|
+
await storage.clearTokens();
|
|
110
110
|
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
const accessToken = await storage.getAccessToken();
|
|
112
|
+
const refreshToken = await storage.getRefreshToken();
|
|
113
113
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
114
|
+
expect(accessToken).toBeNull();
|
|
115
|
+
expect(refreshToken).toBeNull();
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
118
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
119
|
+
describe('custom storage keys', () => {
|
|
120
|
+
it('should use custom keys for token storage', async () => {
|
|
121
|
+
const customStorage = new CacheTokenStorage(
|
|
122
|
+
cache,
|
|
123
|
+
'custom_access_key',
|
|
124
|
+
'custom_refresh_key',
|
|
125
|
+
);
|
|
126
126
|
|
|
127
|
-
|
|
128
|
-
|
|
127
|
+
await customStorage.setAccessToken('access-token');
|
|
128
|
+
await customStorage.setRefreshToken('refresh-token');
|
|
129
129
|
|
|
130
|
-
|
|
131
|
-
|
|
130
|
+
const accessToken = await customStorage.getAccessToken();
|
|
131
|
+
const refreshToken = await customStorage.getRefreshToken();
|
|
132
132
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
133
|
+
expect(accessToken).toBe('access-token');
|
|
134
|
+
expect(refreshToken).toBe('refresh-token');
|
|
135
|
+
});
|
|
136
136
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
137
|
+
it('should isolate tokens between different storage instances', async () => {
|
|
138
|
+
const defaultStorage = new CacheTokenStorage(cache);
|
|
139
|
+
const customStorage = new CacheTokenStorage(
|
|
140
|
+
cache,
|
|
141
|
+
'custom_access',
|
|
142
|
+
'custom_refresh',
|
|
143
|
+
);
|
|
144
144
|
|
|
145
|
-
|
|
146
|
-
|
|
145
|
+
await defaultStorage.setAccessToken('default-access');
|
|
146
|
+
await customStorage.setAccessToken('custom-access');
|
|
147
147
|
|
|
148
|
-
|
|
149
|
-
|
|
148
|
+
const defaultToken = await defaultStorage.getAccessToken();
|
|
149
|
+
const customToken = await customStorage.getAccessToken();
|
|
150
150
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
151
|
+
expect(defaultToken).toBe('default-access');
|
|
152
|
+
expect(customToken).toBe('custom-access');
|
|
153
|
+
});
|
|
154
154
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
155
|
+
it('should clear tokens independently with custom keys', async () => {
|
|
156
|
+
const defaultStorage = new CacheTokenStorage(cache);
|
|
157
|
+
const customStorage = new CacheTokenStorage(
|
|
158
|
+
cache,
|
|
159
|
+
'custom_access',
|
|
160
|
+
'custom_refresh',
|
|
161
|
+
);
|
|
162
162
|
|
|
163
|
-
|
|
164
|
-
|
|
163
|
+
await defaultStorage.setAccessToken('default-access');
|
|
164
|
+
await customStorage.setAccessToken('custom-access');
|
|
165
165
|
|
|
166
|
-
|
|
166
|
+
await defaultStorage.clearTokens();
|
|
167
167
|
|
|
168
|
-
|
|
169
|
-
|
|
168
|
+
const defaultToken = await defaultStorage.getAccessToken();
|
|
169
|
+
const customToken = await customStorage.getAccessToken();
|
|
170
170
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
171
|
+
expect(defaultToken).toBeNull();
|
|
172
|
+
expect(customToken).toBe('custom-access');
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
175
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
176
|
+
describe('integration with real cache', () => {
|
|
177
|
+
it('should work with multiple cache instances', async () => {
|
|
178
|
+
const cache1 = new InMemoryCache<string>();
|
|
179
|
+
const cache2 = new InMemoryCache<string>();
|
|
180
180
|
|
|
181
|
-
|
|
182
|
-
|
|
181
|
+
const storage1 = new CacheTokenStorage(cache1);
|
|
182
|
+
const storage2 = new CacheTokenStorage(cache2);
|
|
183
183
|
|
|
184
|
-
|
|
185
|
-
|
|
184
|
+
await storage1.setAccessToken('token-1');
|
|
185
|
+
await storage2.setAccessToken('token-2');
|
|
186
186
|
|
|
187
|
-
|
|
188
|
-
|
|
187
|
+
const token1 = await storage1.getAccessToken();
|
|
188
|
+
const token2 = await storage2.getAccessToken();
|
|
189
189
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
190
|
+
expect(token1).toBe('token-1');
|
|
191
|
+
expect(token2).toBe('token-2');
|
|
192
|
+
});
|
|
193
193
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
194
|
+
it('should maintain token state across operations', async () => {
|
|
195
|
+
await storage.setAccessToken('initial-access');
|
|
196
|
+
await storage.setRefreshToken('initial-refresh');
|
|
197
197
|
|
|
198
|
-
|
|
199
|
-
|
|
198
|
+
let accessToken = await storage.getAccessToken();
|
|
199
|
+
let refreshToken = await storage.getRefreshToken();
|
|
200
200
|
|
|
201
|
-
|
|
202
|
-
|
|
201
|
+
expect(accessToken).toBe('initial-access');
|
|
202
|
+
expect(refreshToken).toBe('initial-refresh');
|
|
203
203
|
|
|
204
|
-
|
|
204
|
+
await storage.setAccessToken('updated-access');
|
|
205
205
|
|
|
206
|
-
|
|
207
|
-
|
|
206
|
+
accessToken = await storage.getAccessToken();
|
|
207
|
+
refreshToken = await storage.getRefreshToken();
|
|
208
208
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
209
|
+
expect(accessToken).toBe('updated-access');
|
|
210
|
+
expect(refreshToken).toBe('initial-refresh');
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
213
|
});
|