first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,147 @@
|
||||
import { ApplicationError } from '@n8n/errors';
|
||||
import type {
|
||||
IAuthenticateGeneric,
|
||||
ICredentialDataDecryptedObject,
|
||||
ICredentialTestRequest,
|
||||
ICredentialType,
|
||||
IHttpRequestHelper,
|
||||
INodeProperties,
|
||||
Icon,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export class ZscalerZiaApi implements ICredentialType {
|
||||
name = 'zscalerZiaApi';
|
||||
|
||||
displayName = 'Zscaler ZIA API';
|
||||
|
||||
documentationUrl = 'zscalerzia';
|
||||
|
||||
icon: Icon = 'file:icons/Zscaler.svg';
|
||||
|
||||
httpRequestNode = {
|
||||
name: 'Zscaler ZIA',
|
||||
docsUrl: 'https://help.zscaler.com/zia/getting-started-zia-api',
|
||||
apiBaseUrl: '',
|
||||
};
|
||||
|
||||
properties: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Cookie',
|
||||
name: 'cookie',
|
||||
type: 'hidden',
|
||||
typeOptions: {
|
||||
expirable: true,
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Base URL',
|
||||
name: 'baseUrl',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'e.g. zsapi.zscalerthree.net',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
displayName: 'Username',
|
||||
name: 'username',
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
displayName: 'Password',
|
||||
name: 'password',
|
||||
type: 'string',
|
||||
typeOptions: { password: true },
|
||||
default: '',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
displayName: 'Api Key',
|
||||
name: 'apiKey',
|
||||
type: 'string',
|
||||
typeOptions: {
|
||||
password: true,
|
||||
},
|
||||
default: '',
|
||||
required: true,
|
||||
},
|
||||
];
|
||||
|
||||
async preAuthentication(this: IHttpRequestHelper, credentials: ICredentialDataDecryptedObject) {
|
||||
const { baseUrl, username, password, apiKey } = credentials;
|
||||
|
||||
const url = (baseUrl as string).endsWith('/')
|
||||
? (baseUrl as string).slice(0, -1)
|
||||
: (baseUrl as string);
|
||||
|
||||
const now = Date.now().toString();
|
||||
|
||||
const obfuscate = (key: string, timestamp: string) => {
|
||||
const high = timestamp.substring(timestamp.length - 6);
|
||||
let low = (parseInt(high) >> 1).toString();
|
||||
|
||||
let obfuscatedApiKey = '';
|
||||
while (low.length < 6) {
|
||||
low = '0' + low;
|
||||
}
|
||||
|
||||
for (let i = 0; i < high.length; i++) {
|
||||
obfuscatedApiKey += key.charAt(parseInt(high.charAt(i)));
|
||||
}
|
||||
for (let j = 0; j < low.length; j++) {
|
||||
obfuscatedApiKey += key.charAt(parseInt(low.charAt(j)) + 2);
|
||||
}
|
||||
|
||||
return obfuscatedApiKey;
|
||||
};
|
||||
|
||||
const response = await this.helpers.httpRequest({
|
||||
method: 'POST',
|
||||
baseURL: `https://${url}`,
|
||||
url: '/api/v1/authenticatedSession',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Cache-Control': 'no-cache',
|
||||
},
|
||||
body: {
|
||||
apiKey: obfuscate(apiKey as string, now),
|
||||
username,
|
||||
password,
|
||||
timestamp: now,
|
||||
},
|
||||
returnFullResponse: true,
|
||||
});
|
||||
|
||||
const headers = response.headers;
|
||||
|
||||
const cookie = (headers['set-cookie'] as string[])
|
||||
?.find((entrt) => entrt.includes('JSESSIONID'))
|
||||
?.split(';')
|
||||
?.find((entry) => entry.includes('JSESSIONID'));
|
||||
|
||||
if (!cookie) {
|
||||
throw new ApplicationError('No cookie returned. Please check your credentials.', {
|
||||
level: 'warning',
|
||||
});
|
||||
}
|
||||
|
||||
return { cookie };
|
||||
}
|
||||
|
||||
authenticate: IAuthenticateGeneric = {
|
||||
type: 'generic',
|
||||
properties: {
|
||||
headers: {
|
||||
Cookie: '={{$credentials.cookie}}',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
test: ICredentialTestRequest = {
|
||||
request: {
|
||||
url: '=https://{{$credentials.baseUrl}}/api/v1/authSettings/exemptedUrls',
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user