Skip to content

Commit

Permalink
feat(core): Add support for digestAuth to httpRequest and declarative…
Browse files Browse the repository at this point in the history
… style (#5676)

feat(core): Add support to digestAuth to httpRequest and declarative style
  • Loading branch information
janober authored Apr 19, 2023
1 parent f9b3aea commit 62f993c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/cli/src/CredentialsHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
21 changes: 19 additions & 2 deletions packages/core/src/NodeExecuteFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -842,6 +858,7 @@ async function httpRequest(
statusMessage: result.statusText,
};
}

return result.data;
}

Expand Down
3 changes: 3 additions & 0 deletions packages/workflow/src/Interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ export interface IRequestOptionsSimplified {
auth?: {
username: string;
password: string;
sendImmediately?: boolean;
};
body: IDataObject;
headers: IDataObject;
Expand All @@ -182,6 +183,7 @@ export interface IRequestOptionsSimplifiedAuth {
auth?: {
username: string;
password: string;
sendImmediately?: boolean;
};
body?: IDataObject;
headers?: IDataObject;
Expand Down Expand Up @@ -501,6 +503,7 @@ export interface IHttpRequestOptions {
auth?: {
username: string;
password: string;
sendImmediately?: boolean;
};
disableFollowRedirect?: boolean;
encoding?: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream';
Expand Down

0 comments on commit 62f993c

Please sign in to comment.