mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-10 06:34:05 -08:00
86 lines
1.8 KiB
TypeScript
86 lines
1.8 KiB
TypeScript
import type {
|
|
IAuthenticateGeneric,
|
|
ICredentialDataDecryptedObject,
|
|
ICredentialTestRequest,
|
|
ICredentialType,
|
|
IHttpRequestHelper,
|
|
INodeProperties,
|
|
} from 'n8n-workflow';
|
|
|
|
export class CrowdStrikeOAuth2Api implements ICredentialType {
|
|
name = 'crowdStrikeOAuth2Api';
|
|
|
|
displayName = 'CrowdStrike OAuth2 API';
|
|
|
|
documentationUrl = 'crowdstrike';
|
|
|
|
icon = 'file:icons/CrowdStrike.svg';
|
|
|
|
properties: INodeProperties[] = [
|
|
{
|
|
displayName: 'Session Token',
|
|
name: 'sessionToken',
|
|
type: 'hidden',
|
|
|
|
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',
|
|
url: `${url.endsWith('/') ? url.slice(0, -1) : url}/oauth2/token?client_id=${
|
|
credentials.clientId
|
|
}&client_secret=${credentials.clientSecret}`,
|
|
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',
|
|
},
|
|
};
|
|
}
|