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:
Jan Oberhauser 2023-04-19 13:44:41 +02:00 committed by GitHub
parent f9b3aeac44
commit 62f993c84f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 3 deletions

View file

@ -224,7 +224,7 @@ export class CredentialsHelper extends ICredentialsHelper {
node: INode,
defaultTimezone: string,
): string {
if (parameterValue.charAt(0) !== '=') {
if (typeof parameterValue !== 'string' || parameterValue.charAt(0) !== '=') {
return parameterValue;
}

View file

@ -825,15 +825,31 @@ function convertN8nRequestToAxios(n8nRequest: IHttpRequestOptions): AxiosRequest
async function httpRequest(
requestOptions: IHttpRequestOptions,
): Promise<IN8nHttpFullResponse | IN8nHttpResponse> {
const axiosRequest = convertN8nRequestToAxios(requestOptions);
let axiosRequest = convertN8nRequestToAxios(requestOptions);
if (
axiosRequest.data === undefined ||
(axiosRequest.method !== undefined && axiosRequest.method.toUpperCase() === 'GET')
) {
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) {
return {
body: result.data,
@ -842,6 +858,7 @@ async function httpRequest(
statusMessage: result.statusText,
};
}
return result.data;
}

View file

@ -172,6 +172,7 @@ export interface IRequestOptionsSimplified {
auth?: {
username: string;
password: string;
sendImmediately?: boolean;
};
body: IDataObject;
headers: IDataObject;
@ -182,6 +183,7 @@ export interface IRequestOptionsSimplifiedAuth {
auth?: {
username: string;
password: string;
sendImmediately?: boolean;
};
body?: IDataObject;
headers?: IDataObject;
@ -501,6 +503,7 @@ export interface IHttpRequestOptions {
auth?: {
username: string;
password: string;
sendImmediately?: boolean;
};
disableFollowRedirect?: boolean;
encoding?: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream';