mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-12 21:37:32 -08:00
fix(core): OAuth1 authentication fix for Clever Cloud API (#6847)
This commit is contained in:
parent
75be1a9c0d
commit
5ab30fdd95
|
@ -923,7 +923,19 @@ export class Server extends AbstractServer {
|
||||||
signature_method: signatureMethod,
|
signature_method: signatureMethod,
|
||||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||||
hash_function(base, key) {
|
hash_function(base, key) {
|
||||||
const algorithm = signatureMethod === 'HMAC-SHA1' ? 'sha1' : 'sha256';
|
let algorithm: string;
|
||||||
|
switch (signatureMethod) {
|
||||||
|
case 'HMAC-SHA256':
|
||||||
|
algorithm = 'sha256';
|
||||||
|
break;
|
||||||
|
case 'HMAC-SHA512':
|
||||||
|
algorithm = 'sha512';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
algorithm = 'sha1';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return createHmac(algorithm, key).update(base).digest('base64');
|
return createHmac(algorithm, key).update(base).digest('base64');
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -949,15 +961,17 @@ export class Server extends AbstractServer {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
options.headers = data;
|
options.headers = data;
|
||||||
|
|
||||||
const { data: response } = await axios.request(options as Partial<AxiosRequestConfig>);
|
const response = await axios.request(options as Partial<AxiosRequestConfig>);
|
||||||
|
|
||||||
// Response comes as x-www-form-urlencoded string so convert it to JSON
|
// Response comes as x-www-form-urlencoded string so convert it to JSON
|
||||||
|
|
||||||
const paramsParser = new URLSearchParams(response);
|
const paramsParser = new URLSearchParams(response.data);
|
||||||
|
|
||||||
const responseJson = Object.fromEntries(paramsParser.entries());
|
const responseJson = Object.fromEntries(paramsParser.entries());
|
||||||
|
|
||||||
const returnUri = `${oauthCredentials.authUrl}?oauth_token=${responseJson.oauth_token}`;
|
const returnUri = `${oauthCredentials.authUrl as string}?oauth_token=${
|
||||||
|
responseJson.oauth_token
|
||||||
|
}`;
|
||||||
|
|
||||||
// Encrypt the data
|
// Encrypt the data
|
||||||
const credentials = new Credentials(
|
const credentials = new Credentials(
|
||||||
|
|
|
@ -1334,7 +1334,18 @@ export async function requestOAuth1(
|
||||||
},
|
},
|
||||||
signature_method: credentials.signatureMethod as string,
|
signature_method: credentials.signatureMethod as string,
|
||||||
hash_function(base, key) {
|
hash_function(base, key) {
|
||||||
const algorithm = credentials.signatureMethod === 'HMAC-SHA1' ? 'sha1' : 'sha256';
|
let algorithm: string;
|
||||||
|
switch (credentials.signatureMethod) {
|
||||||
|
case 'HMAC-SHA256':
|
||||||
|
algorithm = 'sha256';
|
||||||
|
break;
|
||||||
|
case 'HMAC-SHA512':
|
||||||
|
algorithm = 'sha512';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
algorithm = 'sha1';
|
||||||
|
break;
|
||||||
|
}
|
||||||
return createHmac(algorithm, key).update(base).digest('base64');
|
return createHmac(algorithm, key).update(base).digest('base64');
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue