Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): Add support for digestAuth to httpRequest and declarative style #5676

Merged
merged 1 commit into from Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cli/src/CredentialsHelper.ts
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
Expand Up @@ -813,15 +813,31 @@
async function httpRequest(
requestOptions: IHttpRequestOptions,
): Promise<IN8nHttpFullResponse | IN8nHttpResponse> {
const axiosRequest = convertN8nRequestToAxios(requestOptions);
let axiosRequest = convertN8nRequestToAxios(requestOptions);

Check warning on line 816 in packages/core/src/NodeExecuteFunctions.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/NodeExecuteFunctions.ts#L816

Added line #L816 was not covered by tests
if (
axiosRequest.data === undefined ||
(axiosRequest.method !== undefined && axiosRequest.method.toUpperCase() === 'GET')
) {
delete axiosRequest.data;
}
let result: AxiosResponse<any>;
try {
result = await axios(axiosRequest);

Check warning on line 825 in packages/core/src/NodeExecuteFunctions.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/NodeExecuteFunctions.ts#L824-L825

Added lines #L824 - L825 were not covered by tests
} catch (error) {
if (requestOptions.auth?.sendImmediately === false) {
const { response } = error;

Check warning on line 828 in packages/core/src/NodeExecuteFunctions.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/NodeExecuteFunctions.ts#L828

Added line #L828 was not covered by tests
if (response?.status !== 401 || !response.headers['www-authenticate']?.includes('nonce')) {
throw error;

Check warning on line 830 in packages/core/src/NodeExecuteFunctions.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/NodeExecuteFunctions.ts#L830

Added line #L830 was not covered by tests
}

const { auth } = axiosRequest;
delete axiosRequest.auth;
axiosRequest = digestAuthAxiosConfig(axiosRequest, response, auth);
result = await axios(axiosRequest);

Check warning on line 836 in packages/core/src/NodeExecuteFunctions.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/NodeExecuteFunctions.ts#L833-L836

Added lines #L833 - L836 were not covered by tests
}
throw error;

Check warning on line 838 in packages/core/src/NodeExecuteFunctions.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/NodeExecuteFunctions.ts#L838

Added line #L838 was not covered by tests
}

const result = await axios(axiosRequest);
if (requestOptions.returnFullResponse) {
return {
body: result.data,
Expand All @@ -830,6 +846,7 @@
statusMessage: result.statusText,
};
}

return result.data;
}

Expand Down
3 changes: 3 additions & 0 deletions packages/workflow/src/Interfaces.ts
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