@jskit-ai/auth-provider-supabase-core 0.2.2 → 0.2.3
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/package.json
CHANGED
|
@@ -892,7 +892,7 @@ function createService(options) {
|
|
|
892
892
|
resolveDevAuthSecurityStatus
|
|
893
893
|
});
|
|
894
894
|
|
|
895
|
-
async function authenticateRequest(request, { syncProfile = true } = {}) {
|
|
895
|
+
async function authenticateRequest(request, { syncProfile = true, refreshSession = true } = {}) {
|
|
896
896
|
const { accessToken, refreshToken } = resolveRequestSessionTokens(request);
|
|
897
897
|
// Without sync, a login whose app profile does not exist yet is not signed in.
|
|
898
898
|
const signedIn = (profile, session = null) => (profile
|
|
@@ -957,6 +957,18 @@ function createService(options) {
|
|
|
957
957
|
};
|
|
958
958
|
}
|
|
959
959
|
|
|
960
|
+
// A caller that cannot store a refreshed session, such as a realtime socket,
|
|
961
|
+
// must not spend the single-use refresh token; it is told to refresh first.
|
|
962
|
+
if (!refreshSession) {
|
|
963
|
+
return {
|
|
964
|
+
authenticated: false,
|
|
965
|
+
refreshRequired: true,
|
|
966
|
+
clearSession: false,
|
|
967
|
+
session: null,
|
|
968
|
+
transientFailure: false
|
|
969
|
+
};
|
|
970
|
+
}
|
|
971
|
+
|
|
960
972
|
const supabase = getSupabaseClient();
|
|
961
973
|
let refreshResponse;
|
|
962
974
|
try {
|
|
@@ -248,6 +248,36 @@ test("authentication without profile sync reads the existing profile", async (t)
|
|
|
248
248
|
assert.equal(syncCalls, 1);
|
|
249
249
|
});
|
|
250
250
|
|
|
251
|
+
test("a caller that cannot store a refreshed session is told to refresh instead of spending the token", async (t) => {
|
|
252
|
+
const tokenRequests = [];
|
|
253
|
+
const supabase = createServer((request, response) => {
|
|
254
|
+
tokenRequests.push(request.url);
|
|
255
|
+
response.statusCode = 400;
|
|
256
|
+
response.setHeader("content-type", "application/json");
|
|
257
|
+
response.end(JSON.stringify({ error: "invalid_grant", error_description: "Invalid Refresh Token" }));
|
|
258
|
+
});
|
|
259
|
+
supabase.listen(0, "127.0.0.1");
|
|
260
|
+
await once(supabase, "listening");
|
|
261
|
+
t.after(() => new Promise((resolve) => supabase.close(resolve)));
|
|
262
|
+
const authService = createServiceFixture({
|
|
263
|
+
authProvider: { id: "supabase", supabaseUrl: `http://127.0.0.1:${supabase.address().port}`, supabasePublishableKey: "publishable-key" }
|
|
264
|
+
});
|
|
265
|
+
// The access cookie is gone once its token expires; the refresh cookie remains.
|
|
266
|
+
const request = { cookies: { sb_refresh_token: "R1" } };
|
|
267
|
+
|
|
268
|
+
assert.deepEqual(await authService.authenticateRequest(request, { refreshSession: false }), {
|
|
269
|
+
authenticated: false,
|
|
270
|
+
refreshRequired: true,
|
|
271
|
+
clearSession: false,
|
|
272
|
+
session: null,
|
|
273
|
+
transientFailure: false
|
|
274
|
+
});
|
|
275
|
+
assert.deepEqual(tokenRequests, []);
|
|
276
|
+
|
|
277
|
+
await authService.authenticateRequest(request);
|
|
278
|
+
assert.deepEqual(tokenRequests, ["/auth/v1/token?grant_type=refresh_token"]);
|
|
279
|
+
});
|
|
280
|
+
|
|
251
281
|
test("logout is local-only when no session cookies are present", async () => {
|
|
252
282
|
const authService = createServiceFixture();
|
|
253
283
|
|