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 {
|
||||
ApplicationError,
|
||||
type ICredentialDataDecryptedObject,
|
||||
|
@ -64,11 +65,13 @@ export class MicrosoftCosmosDbSharedKeyApi implements ICredentialType {
|
|||
}
|
||||
|
||||
requestOptions.headers ??= {};
|
||||
|
||||
const date = new Date().toUTCString().toLowerCase();
|
||||
requestOptions.headers = {
|
||||
...requestOptions.headers,
|
||||
'x-ms-date': date,
|
||||
'x-ms-version': '2018-12-31',
|
||||
'Cache-Control': 'no-cache',
|
||||
};
|
||||
|
||||
if (credentials.sessionToken) {
|
||||
|
@ -76,7 +79,6 @@ export class MicrosoftCosmosDbSharedKeyApi implements ICredentialType {
|
|||
}
|
||||
|
||||
let url;
|
||||
|
||||
if (requestOptions.url) {
|
||||
url = new URL(requestOptions.baseURL + requestOptions.url);
|
||||
//@ts-ignore
|
||||
|
@ -86,7 +88,6 @@ export class MicrosoftCosmosDbSharedKeyApi implements ICredentialType {
|
|||
}
|
||||
|
||||
const pathSegments = url?.pathname.split('/').filter((segment) => segment);
|
||||
|
||||
let resourceType = '';
|
||||
let resourceId = '';
|
||||
|
||||
|
@ -116,22 +117,21 @@ export class MicrosoftCosmosDbSharedKeyApi implements ICredentialType {
|
|||
throw new ApplicationError('Unable to determine resourceType and resourceId from the URL.');
|
||||
}
|
||||
|
||||
console.log('resourceId', resourceId);
|
||||
console.log('resourceType', resourceType);
|
||||
|
||||
if (requestOptions.method) {
|
||||
const authToken = getAuthorizationTokenUsingMasterKey(
|
||||
let authToken = '';
|
||||
|
||||
if (credentials.key) {
|
||||
authToken = getAuthorizationTokenUsingMasterKey(
|
||||
requestOptions.method,
|
||||
resourceType,
|
||||
resourceId,
|
||||
date,
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -45,17 +45,12 @@ export function getAuthorizationTokenUsingMasterKey(
|
|||
verb: string,
|
||||
resourceType: string,
|
||||
resourceId: string,
|
||||
date: string,
|
||||
masterKey: string,
|
||||
): string {
|
||||
const key = Buffer.from(masterKey, 'base64');
|
||||
const payload =
|
||||
`${verb.toLowerCase()}\n` +
|
||||
`${resourceType.toLowerCase()}\n` +
|
||||
`${resourceId}\n` +
|
||||
`${date.toLowerCase()}\n` +
|
||||
'\n';
|
||||
const date = new Date().toUTCString().toLowerCase();
|
||||
|
||||
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 signature = hmacSha256.update(payload, 'utf8').digest('base64');
|
||||
|
||||
|
|
Loading…
Reference in a new issue