mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
fix(core): Fix HTTP Digest Auth for responses without an opaque parameter (#4806)
This commit is contained in:
parent
a04f838117
commit
6fac502f9e
|
@ -522,9 +522,9 @@ function digestAuthAxiosConfig(
|
||||||
const realm: string = authDetails
|
const realm: string = authDetails
|
||||||
.find((el: any) => el[0].toLowerCase().indexOf('realm') > -1)[1]
|
.find((el: any) => el[0].toLowerCase().indexOf('realm') > -1)[1]
|
||||||
.replace(/"/g, '');
|
.replace(/"/g, '');
|
||||||
const opaque: string = authDetails
|
// If authDeatials does not have opaque, we should not add it to authorization.
|
||||||
.find((el: any) => el[0].toLowerCase().indexOf('opaque') > -1)[1]
|
const opaqueKV = authDetails.find((el: any) => el[0].toLowerCase().indexOf('opaque') > -1);
|
||||||
.replace(/"/g, '');
|
const opaque: string = opaqueKV ? opaqueKV[1].replace(/"/g, '') : undefined;
|
||||||
const nonce: string = authDetails
|
const nonce: string = authDetails
|
||||||
.find((el: any) => el[0].toLowerCase().indexOf('nonce') > -1)[1]
|
.find((el: any) => el[0].toLowerCase().indexOf('nonce') > -1)[1]
|
||||||
.replace(/"/g, '');
|
.replace(/"/g, '');
|
||||||
|
@ -542,10 +542,14 @@ function digestAuthAxiosConfig(
|
||||||
.createHash('md5')
|
.createHash('md5')
|
||||||
.update(`${ha1}:${nonce}:${nonceCount}:${cnonce}:auth:${ha2}`)
|
.update(`${ha1}:${nonce}:${nonceCount}:${cnonce}:auth:${ha2}`)
|
||||||
.digest('hex');
|
.digest('hex');
|
||||||
const authorization =
|
let authorization =
|
||||||
`Digest username="${auth?.username as string}",realm="${realm}",` +
|
`Digest username="${auth?.username as string}",realm="${realm}",` +
|
||||||
`nonce="${nonce}",uri="${path}",qop="auth",algorithm="MD5",` +
|
`nonce="${nonce}",uri="${path}",qop="auth",algorithm="MD5",` +
|
||||||
`response="${response}",nc="${nonceCount}",cnonce="${cnonce}",opaque="${opaque}"`;
|
`response="${response}",nc="${nonceCount}",cnonce="${cnonce}"`;
|
||||||
|
// Only when opaque exists, add it to authorization.
|
||||||
|
if (opaque) {
|
||||||
|
authorization += `,opaque="${opaque}"`;
|
||||||
|
}
|
||||||
if (axiosConfig.headers) {
|
if (axiosConfig.headers) {
|
||||||
axiosConfig.headers.authorization = authorization;
|
axiosConfig.headers.authorization = authorization;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue