[grade=B] feat(auth): onboard missing credentials into encrypted vault
This commit is contained in:
@@ -330,17 +330,22 @@ module.exports = function configureMiddleware(app, {
|
||||
const ssoHandoffTokens = new Map();
|
||||
const SSO_HANDOFF_TTL_MS = 60 * 1000;
|
||||
|
||||
function createHandoffToken() {
|
||||
function createHandoffToken(expectedHost = null) {
|
||||
const token = crypto.randomBytes(24).toString('base64url');
|
||||
ssoHandoffTokens.set(token, { exp: Date.now() + SSO_HANDOFF_TTL_MS });
|
||||
ssoHandoffTokens.set(token, {
|
||||
exp: Date.now() + SSO_HANDOFF_TTL_MS,
|
||||
expectedHost: expectedHost ? String(expectedHost).toLowerCase() : null,
|
||||
});
|
||||
return token;
|
||||
}
|
||||
|
||||
function redeemHandoffToken(token) {
|
||||
function redeemHandoffToken(token, actualHost = null) {
|
||||
if (!token) return false;
|
||||
const entry = ssoHandoffTokens.get(token);
|
||||
ssoHandoffTokens.delete(token); // one-time use regardless of outcome
|
||||
return !!entry && entry.exp > Date.now();
|
||||
if (!entry || entry.exp <= Date.now()) return false;
|
||||
if (!entry.expectedHost) return true;
|
||||
return !!actualHost && entry.expectedHost === String(actualHost).toLowerCase();
|
||||
}
|
||||
|
||||
function setHostOnlySessionCookie(res, durationKey) {
|
||||
|
||||
Reference in New Issue
Block a user