2023-07-31 01:26:38 -07:00
|
|
|
import type {
|
|
|
|
IAuthenticateGeneric,
|
|
|
|
ICredentialDataDecryptedObject,
|
|
|
|
ICredentialTestRequest,
|
|
|
|
ICredentialType,
|
|
|
|
IHttpRequestHelper,
|
|
|
|
INodeProperties,
|
|
|
|
} from 'n8n-workflow';
|
|
|
|
|
|
|
|
export class CrowdStrikeOAuth2Api implements ICredentialType {
|
|
|
|
name = 'crowdStrikeOAuth2Api';
|
|
|
|
|
|
|
|
displayName = 'CrowdStrike OAuth2 API';
|
|
|
|
|
2023-08-09 06:16:11 -07:00
|
|
|
documentationUrl = 'crowdstrike';
|
|
|
|
|
2023-07-31 01:26:38 -07:00
|
|
|
icon = 'file:icons/CrowdStrike.svg';
|
|
|
|
|
2023-11-13 03:11:16 -08:00
|
|
|
httpRequestNode = {
|
|
|
|
name: 'CrowdStrike',
|
|
|
|
docsUrl: 'https://developer.crowdstrike.com/',
|
|
|
|
apiBaseUrl: '',
|
|
|
|
};
|
|
|
|
|
2023-07-31 01:26:38 -07:00
|
|
|
properties: INodeProperties[] = [
|
|
|
|
{
|
|
|
|
displayName: 'Session Token',
|
|
|
|
name: 'sessionToken',
|
|
|
|
type: 'hidden',
|
2023-08-09 01:10:08 -07:00
|
|
|
|
2023-07-31 01:26:38 -07:00
|
|
|
typeOptions: {
|
|
|
|
expirable: true,
|
|
|
|
},
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'URL',
|
|
|
|
name: 'url',
|
|
|
|
type: 'string',
|
|
|
|
required: true,
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Client ID',
|
|
|
|
name: 'clientId',
|
|
|
|
type: 'string',
|
|
|
|
required: true,
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Client Secret',
|
|
|
|
name: 'clientSecret',
|
|
|
|
type: 'string',
|
|
|
|
typeOptions: {
|
|
|
|
password: true,
|
|
|
|
},
|
|
|
|
required: true,
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
async preAuthentication(this: IHttpRequestHelper, credentials: ICredentialDataDecryptedObject) {
|
|
|
|
const url = credentials.url as string;
|
|
|
|
const { access_token } = (await this.helpers.httpRequest({
|
|
|
|
method: 'POST',
|
2024-04-16 00:39:22 -07:00
|
|
|
url: `${url.endsWith('/') ? url.slice(0, -1) : url}/oauth2/token`,
|
|
|
|
body: {
|
|
|
|
client_id: credentials.clientId,
|
|
|
|
client_secret: credentials.clientSecret,
|
|
|
|
},
|
2023-07-31 01:26:38 -07:00
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
},
|
|
|
|
})) as { access_token: string };
|
|
|
|
return { sessionToken: access_token };
|
|
|
|
}
|
|
|
|
|
|
|
|
authenticate: IAuthenticateGeneric = {
|
|
|
|
type: 'generic',
|
|
|
|
properties: {
|
|
|
|
headers: {
|
|
|
|
Authorization: '=Bearer {{$credentials.sessionToken}}',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
test: ICredentialTestRequest = {
|
|
|
|
request: {
|
|
|
|
baseURL: '={{$credentials?.url}}',
|
|
|
|
url: 'user-management/queries/users/v1',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|