remix-utils
Advanced tools
Comparing version
@@ -21,17 +21,7 @@ import { sha256 } from "@oslojs/crypto/sha2"; | ||
let authorization = getAuthorization(request); | ||
if (!authorization) { | ||
throw Response.json(await getInvalidUserMessage({ request, context }), { | ||
status: 401, | ||
statusText: "Unauthorized", | ||
headers: { "WWW-Authenticate": `Basic realm="${realm}"` }, | ||
}); | ||
} | ||
if (!authorization) | ||
throw await unauthorized(request, context); | ||
let { username, password } = authorization; | ||
if (!username || !password) { | ||
throw Response.json(await getInvalidUserMessage({ request, context }), { | ||
status: 401, | ||
statusText: "Unauthorized", | ||
headers: { "WWW-Authenticate": `Basic realm="${realm}"` }, | ||
}); | ||
} | ||
if (!username || !password) | ||
throw await unauthorized(request, context); | ||
if (verifyUserInOptions) { | ||
@@ -50,7 +40,9 @@ let isValid = await options.verifyUser(username, password, { | ||
for (let user of options.user) { | ||
if (user.username === username && user.password === password) { | ||
if (await validateCredentials(user, username, password)) { | ||
context.set(userContext, username); | ||
return await next(); | ||
} | ||
if (user.username !== username) | ||
continue; | ||
if (user.password !== password) | ||
continue; | ||
if (await validateCredentials(user, username, password)) { | ||
context.set(userContext, username); | ||
return await next(); | ||
} | ||
@@ -66,9 +58,3 @@ } | ||
} | ||
throw Response.json(await getInvalidUserMessage({ request, context }), { | ||
status: 401, | ||
statusText: "Unauthorized", | ||
headers: { | ||
"WWW-Authenticate": `Basic realm="${realm}"`, | ||
}, | ||
}); | ||
throw await unauthorized(request, context); | ||
}, | ||
@@ -97,2 +83,10 @@ function getUser(context) { | ||
} | ||
async function unauthorized(request, context) { | ||
let message = await getInvalidUserMessage({ request, context }); | ||
return Response.json(message, { | ||
status: 401, | ||
statusText: "Unauthorized", | ||
headers: { "WWW-Authenticate": `Basic realm="${realm}"` }, | ||
}); | ||
} | ||
} | ||
@@ -99,0 +93,0 @@ async function timingSafeEqual(a, b, hashFunction) { |
{ | ||
"name": "remix-utils", | ||
"version": "8.4.1", | ||
"version": "8.5.0", | ||
"license": "MIT", | ||
@@ -26,2 +26,6 @@ "engines": { | ||
}, | ||
"./middleware/jwk-auth": { | ||
"types": "./build/server/middleware/jwk-auth.d.ts", | ||
"default": "./build/server/middleware/jwk-auth.js" | ||
}, | ||
"./middleware/logger": { | ||
@@ -238,2 +242,3 @@ "types": "./build/server/middleware/logger.d.ts", | ||
"@edgefirst-dev/batcher": "^1.0.0", | ||
"@edgefirst-dev/jwt": "^1.2.0", | ||
"@edgefirst-dev/server-timing": "^0.0.1", | ||
@@ -252,2 +257,5 @@ "@oslojs/crypto": "^1.0.1", | ||
}, | ||
"@edgefirst-dev/jwt": { | ||
"optional": true | ||
}, | ||
"@edgefirst-dev/server-timing": { | ||
@@ -282,4 +290,6 @@ "optional": true | ||
"@edgefirst-dev/batcher": "^1.0.1", | ||
"@edgefirst-dev/jwt": "^1.2.0", | ||
"@edgefirst-dev/server-timing": "^0.0.1", | ||
"@happy-dom/global-registrator": "^17.4.3", | ||
"@mjackson/file-storage": "^0.6.1", | ||
"@oslojs/crypto": "^1.0.1", | ||
@@ -286,0 +296,0 @@ "@oslojs/encoding": "^1.1.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
330081
3.94%156
1.96%4303
3.09%2685
6.04%11
10%25
8.7%