Refactor auth interpolation in request utils

This commit is contained in:
Sanjai Kumar 2024-09-26 15:42:11 +05:30
parent f49eddf7ec
commit 876c763486

View File

@ -26,7 +26,7 @@ const interpolateRequest = (request, combinedVars) => {
}; };
const interpolateAuth = (auth) => { const interpolateAuth = (auth) => {
if (auth.type === 'oauth2') { if (auth.mode === 'oauth2') {
const { oauth2 } = auth; const { oauth2 } = auth;
if (oauth2?.grantType) { if (oauth2?.grantType) {
let username, password, scope, clientId, clientSecret; let username, password, scope, clientId, clientSecret;
@ -81,17 +81,25 @@ const interpolateRequest = (request, combinedVars) => {
break; break;
} }
} }
} else if (auth.type === 'basic') { } else if (auth.mode === 'basic') {
auth.username = interpolate(auth.username, combinedVars); const { basic } = auth;
auth.password = interpolate(auth.password, combinedVars);
} else if (auth.type === 'bearer') { basic.username = interpolate(basic.username, combinedVars);
auth.token = interpolate(auth.token, combinedVars); basic.password = interpolate(basic.password, combinedVars);
} else if (auth.type === 'wsse') { } else if (auth.mode === 'bearer') {
auth.username = interpolate(auth.username, combinedVars); const { bearer } = auth;
auth.password = interpolate(auth.password, combinedVars);
} else if (auth.type === 'digest') { bearer.token = interpolate(bearer.token, combinedVars);
auth.username = interpolate(auth.username, combinedVars); } else if (auth.mode === 'wsse') {
auth.password = interpolate(auth.password, combinedVars); const { wsse } = auth;
wsse.username = interpolate(wsse.username, combinedVars);
wsse.password = interpolate(wsse.password, combinedVars);
} else if (auth.mode === 'digest') {
const { digest } = auth;
digest.username = interpolate(digest.username, combinedVars);
digest.password = interpolate(digest.password, combinedVars);
} }
}; };