mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
Fixed authentication error
This commit is contained in:
parent
d210fcc172
commit
aa6eca12ef
|
@ -1,3 +1,4 @@
|
||||||
|
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
||||||
import {
|
import {
|
||||||
ApplicationError,
|
ApplicationError,
|
||||||
type ICredentialDataDecryptedObject,
|
type ICredentialDataDecryptedObject,
|
||||||
|
@ -64,11 +65,13 @@ export class MicrosoftCosmosDbSharedKeyApi implements ICredentialType {
|
||||||
}
|
}
|
||||||
|
|
||||||
requestOptions.headers ??= {};
|
requestOptions.headers ??= {};
|
||||||
|
|
||||||
const date = new Date().toUTCString().toLowerCase();
|
const date = new Date().toUTCString().toLowerCase();
|
||||||
requestOptions.headers = {
|
requestOptions.headers = {
|
||||||
...requestOptions.headers,
|
...requestOptions.headers,
|
||||||
'x-ms-date': date,
|
'x-ms-date': date,
|
||||||
'x-ms-version': '2018-12-31',
|
'x-ms-version': '2018-12-31',
|
||||||
|
'Cache-Control': 'no-cache',
|
||||||
};
|
};
|
||||||
|
|
||||||
if (credentials.sessionToken) {
|
if (credentials.sessionToken) {
|
||||||
|
@ -76,7 +79,6 @@ export class MicrosoftCosmosDbSharedKeyApi implements ICredentialType {
|
||||||
}
|
}
|
||||||
|
|
||||||
let url;
|
let url;
|
||||||
|
|
||||||
if (requestOptions.url) {
|
if (requestOptions.url) {
|
||||||
url = new URL(requestOptions.baseURL + requestOptions.url);
|
url = new URL(requestOptions.baseURL + requestOptions.url);
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
|
@ -86,7 +88,6 @@ export class MicrosoftCosmosDbSharedKeyApi implements ICredentialType {
|
||||||
}
|
}
|
||||||
|
|
||||||
const pathSegments = url?.pathname.split('/').filter((segment) => segment);
|
const pathSegments = url?.pathname.split('/').filter((segment) => segment);
|
||||||
|
|
||||||
let resourceType = '';
|
let resourceType = '';
|
||||||
let resourceId = '';
|
let resourceId = '';
|
||||||
|
|
||||||
|
@ -116,22 +117,21 @@ export class MicrosoftCosmosDbSharedKeyApi implements ICredentialType {
|
||||||
throw new ApplicationError('Unable to determine resourceType and resourceId from the URL.');
|
throw new ApplicationError('Unable to determine resourceType and resourceId from the URL.');
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('resourceId', resourceId);
|
|
||||||
console.log('resourceType', resourceType);
|
|
||||||
|
|
||||||
if (requestOptions.method) {
|
if (requestOptions.method) {
|
||||||
const authToken = getAuthorizationTokenUsingMasterKey(
|
let authToken = '';
|
||||||
|
|
||||||
|
if (credentials.key) {
|
||||||
|
authToken = getAuthorizationTokenUsingMasterKey(
|
||||||
requestOptions.method,
|
requestOptions.method,
|
||||||
resourceType,
|
resourceType,
|
||||||
resourceId,
|
resourceId,
|
||||||
date,
|
|
||||||
credentials.key as string,
|
credentials.key as string,
|
||||||
);
|
);
|
||||||
|
|
||||||
requestOptions.headers[HeaderConstants.AUTHORIZATION] = authToken;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Final requestOptions:', requestOptions);
|
requestOptions.headers[HeaderConstants.AUTHORIZATION] = encodeURIComponent(authToken);
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||||
|
}
|
||||||
|
|
||||||
return requestOptions;
|
return requestOptions;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,17 +45,12 @@ export function getAuthorizationTokenUsingMasterKey(
|
||||||
verb: string,
|
verb: string,
|
||||||
resourceType: string,
|
resourceType: string,
|
||||||
resourceId: string,
|
resourceId: string,
|
||||||
date: string,
|
|
||||||
masterKey: string,
|
masterKey: string,
|
||||||
): string {
|
): string {
|
||||||
const key = Buffer.from(masterKey, 'base64');
|
const date = new Date().toUTCString().toLowerCase();
|
||||||
const payload =
|
|
||||||
`${verb.toLowerCase()}\n` +
|
|
||||||
`${resourceType.toLowerCase()}\n` +
|
|
||||||
`${resourceId}\n` +
|
|
||||||
`${date.toLowerCase()}\n` +
|
|
||||||
'\n';
|
|
||||||
|
|
||||||
|
const key = Buffer.from(masterKey, 'base64');
|
||||||
|
const payload = `${verb.toLowerCase()}\n${resourceType.toLowerCase()}\n${resourceId}\n${date.toLowerCase()}\n\n`;
|
||||||
const hmacSha256 = crypto.createHmac('sha256', key);
|
const hmacSha256 = crypto.createHmac('sha256', key);
|
||||||
const signature = hmacSha256.update(payload, 'utf8').digest('base64');
|
const signature = hmacSha256.update(payload, 'utf8').digest('base64');
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue