mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-13 05:47:31 -08:00
feat(core): Add support for digestAuth to httpRequest and declarative style (#5676)
feat(core): Add support to digestAuth to httpRequest and declarative style
This commit is contained in:
parent
f9b3aeac44
commit
62f993c84f
|
@ -224,7 +224,7 @@ export class CredentialsHelper extends ICredentialsHelper {
|
||||||
node: INode,
|
node: INode,
|
||||||
defaultTimezone: string,
|
defaultTimezone: string,
|
||||||
): string {
|
): string {
|
||||||
if (parameterValue.charAt(0) !== '=') {
|
if (typeof parameterValue !== 'string' || parameterValue.charAt(0) !== '=') {
|
||||||
return parameterValue;
|
return parameterValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -825,15 +825,31 @@ function convertN8nRequestToAxios(n8nRequest: IHttpRequestOptions): AxiosRequest
|
||||||
async function httpRequest(
|
async function httpRequest(
|
||||||
requestOptions: IHttpRequestOptions,
|
requestOptions: IHttpRequestOptions,
|
||||||
): Promise<IN8nHttpFullResponse | IN8nHttpResponse> {
|
): Promise<IN8nHttpFullResponse | IN8nHttpResponse> {
|
||||||
const axiosRequest = convertN8nRequestToAxios(requestOptions);
|
let axiosRequest = convertN8nRequestToAxios(requestOptions);
|
||||||
if (
|
if (
|
||||||
axiosRequest.data === undefined ||
|
axiosRequest.data === undefined ||
|
||||||
(axiosRequest.method !== undefined && axiosRequest.method.toUpperCase() === 'GET')
|
(axiosRequest.method !== undefined && axiosRequest.method.toUpperCase() === 'GET')
|
||||||
) {
|
) {
|
||||||
delete axiosRequest.data;
|
delete axiosRequest.data;
|
||||||
}
|
}
|
||||||
|
let result: AxiosResponse<any>;
|
||||||
|
try {
|
||||||
|
result = await axios(axiosRequest);
|
||||||
|
} catch (error) {
|
||||||
|
if (requestOptions.auth?.sendImmediately === false) {
|
||||||
|
const { response } = error;
|
||||||
|
if (response?.status !== 401 || !response.headers['www-authenticate']?.includes('nonce')) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { auth } = axiosRequest;
|
||||||
|
delete axiosRequest.auth;
|
||||||
|
axiosRequest = digestAuthAxiosConfig(axiosRequest, response, auth);
|
||||||
|
result = await axios(axiosRequest);
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
const result = await axios(axiosRequest);
|
|
||||||
if (requestOptions.returnFullResponse) {
|
if (requestOptions.returnFullResponse) {
|
||||||
return {
|
return {
|
||||||
body: result.data,
|
body: result.data,
|
||||||
|
@ -842,6 +858,7 @@ async function httpRequest(
|
||||||
statusMessage: result.statusText,
|
statusMessage: result.statusText,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return result.data;
|
return result.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -172,6 +172,7 @@ export interface IRequestOptionsSimplified {
|
||||||
auth?: {
|
auth?: {
|
||||||
username: string;
|
username: string;
|
||||||
password: string;
|
password: string;
|
||||||
|
sendImmediately?: boolean;
|
||||||
};
|
};
|
||||||
body: IDataObject;
|
body: IDataObject;
|
||||||
headers: IDataObject;
|
headers: IDataObject;
|
||||||
|
@ -182,6 +183,7 @@ export interface IRequestOptionsSimplifiedAuth {
|
||||||
auth?: {
|
auth?: {
|
||||||
username: string;
|
username: string;
|
||||||
password: string;
|
password: string;
|
||||||
|
sendImmediately?: boolean;
|
||||||
};
|
};
|
||||||
body?: IDataObject;
|
body?: IDataObject;
|
||||||
headers?: IDataObject;
|
headers?: IDataObject;
|
||||||
|
@ -501,6 +503,7 @@ export interface IHttpRequestOptions {
|
||||||
auth?: {
|
auth?: {
|
||||||
username: string;
|
username: string;
|
||||||
password: string;
|
password: string;
|
||||||
|
sendImmediately?: boolean;
|
||||||
};
|
};
|
||||||
disableFollowRedirect?: boolean;
|
disableFollowRedirect?: boolean;
|
||||||
encoding?: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream';
|
encoding?: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream';
|
||||||
|
|
Loading…
Reference in a new issue