2023-05-17 01:53:03 -07:00
|
|
|
/* eslint-disable @typescript-eslint/naming-convention */
|
2023-01-27 05:56:56 -08:00
|
|
|
import type { ICredentialDataDecryptedObject } from 'n8n-workflow';
|
2023-05-17 01:53:03 -07:00
|
|
|
import type clientOAuth2 from 'client-oauth2';
|
2022-10-20 08:15:28 -07:00
|
|
|
|
|
|
|
export const getClientCredentialsToken = async (
|
2023-05-17 01:53:03 -07:00
|
|
|
oAuth2Client: clientOAuth2,
|
2022-10-20 08:15:28 -07:00
|
|
|
credentials: ICredentialDataDecryptedObject,
|
2023-05-17 01:53:03 -07:00
|
|
|
): Promise<clientOAuth2.Token> => {
|
2022-10-20 08:15:28 -07:00
|
|
|
const options = {};
|
|
|
|
if (credentials.authentication === 'body') {
|
|
|
|
Object.assign(options, {
|
|
|
|
headers: {
|
|
|
|
Authorization: '',
|
|
|
|
},
|
|
|
|
body: {
|
|
|
|
client_id: credentials.clientId as string,
|
|
|
|
client_secret: credentials.clientSecret as string,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2023-05-17 01:53:03 -07:00
|
|
|
return oAuth2Client.credentials.getToken(options);
|
2022-10-20 08:15:28 -07:00
|
|
|
};
|