@joshuanode/n8n-nodes-cipp 0.0.23 → 0.0.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ICredentialDataDecryptedObject, ICredentialType, IHttpRequestOptions, INodeProperties, Icon } from 'n8n-workflow';
|
|
2
2
|
export declare class CippApi implements ICredentialType {
|
|
3
3
|
name: string;
|
|
4
4
|
displayName: string;
|
|
5
5
|
icon: Icon;
|
|
6
6
|
documentationUrl: string;
|
|
7
|
+
genericAuth: boolean;
|
|
7
8
|
properties: INodeProperties[];
|
|
9
|
+
authenticate(credentials: ICredentialDataDecryptedObject, requestOptions: IHttpRequestOptions): Promise<IHttpRequestOptions>;
|
|
8
10
|
}
|
|
9
11
|
//# sourceMappingURL=CippApi.credentials.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CippApi.credentials.d.ts","sourceRoot":"","sources":["../../credentials/CippApi.credentials.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"CippApi.credentials.d.ts","sourceRoot":"","sources":["../../credentials/CippApi.credentials.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,8BAA8B,EAC9B,eAAe,EAEf,mBAAmB,EACnB,eAAe,EACf,IAAI,EACJ,MAAM,cAAc,CAAC;AA6EtB,qBAAa,OAAQ,YAAW,eAAe;IAC9C,IAAI,SAAa;IACjB,WAAW,SAAkB;IAC7B,IAAI,EAAE,IAAI,CAAmB;IAC7B,gBAAgB,SAAsE;IACtF,WAAW,UAAQ;IAEnB,UAAU,EAAE,eAAe,EAAE,CAqC3B;IAEI,YAAY,CACjB,WAAW,EAAE,8BAA8B,EAC3C,cAAc,EAAE,mBAAmB,GACjC,OAAO,CAAC,mBAAmB,CAAC;CAW/B"}
|
|
@@ -1,11 +1,61 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CippApi = void 0;
|
|
4
|
+
const tokenCache = new Map();
|
|
5
|
+
function getCredentialString(credentials, name) {
|
|
6
|
+
const value = credentials[name];
|
|
7
|
+
if (typeof value !== 'string' || value.trim() === '') {
|
|
8
|
+
throw new Error(`Missing required CIPP credential field: ${name}`);
|
|
9
|
+
}
|
|
10
|
+
return value.trim();
|
|
11
|
+
}
|
|
12
|
+
function getCacheKey(clientId, tenantId) {
|
|
13
|
+
return `${clientId}:${tenantId}`;
|
|
14
|
+
}
|
|
15
|
+
async function getAccessToken(credentials) {
|
|
16
|
+
const tenantId = getCredentialString(credentials, 'tenantId');
|
|
17
|
+
const clientId = getCredentialString(credentials, 'clientId');
|
|
18
|
+
const clientSecret = getCredentialString(credentials, 'clientSecret');
|
|
19
|
+
const cacheKey = getCacheKey(clientId, tenantId);
|
|
20
|
+
const cached = tokenCache.get(cacheKey);
|
|
21
|
+
if (cached && cached.expiresAt > Date.now() + 300000) {
|
|
22
|
+
return cached.accessToken;
|
|
23
|
+
}
|
|
24
|
+
const tokenUrl = `https://login.microsoftonline.com/${tenantId}/oauth2/v2.0/token`;
|
|
25
|
+
const body = new URLSearchParams({
|
|
26
|
+
grant_type: 'client_credentials',
|
|
27
|
+
client_id: clientId,
|
|
28
|
+
client_secret: clientSecret,
|
|
29
|
+
scope: `api://${clientId}/.default`,
|
|
30
|
+
});
|
|
31
|
+
const response = await fetch(tokenUrl, {
|
|
32
|
+
method: 'POST',
|
|
33
|
+
headers: {
|
|
34
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
35
|
+
},
|
|
36
|
+
body,
|
|
37
|
+
});
|
|
38
|
+
const responseBody = (await response.json().catch(() => ({})));
|
|
39
|
+
if (!response.ok || typeof responseBody.access_token !== 'string') {
|
|
40
|
+
tokenCache.delete(cacheKey);
|
|
41
|
+
const message = responseBody.error_description ||
|
|
42
|
+
responseBody.error ||
|
|
43
|
+
`Azure AD token request failed with status ${response.status}`;
|
|
44
|
+
throw new Error(message);
|
|
45
|
+
}
|
|
46
|
+
const expiresIn = typeof responseBody.expires_in === 'number' ? responseBody.expires_in : 3600;
|
|
47
|
+
tokenCache.set(cacheKey, {
|
|
48
|
+
accessToken: responseBody.access_token,
|
|
49
|
+
expiresAt: Date.now() + expiresIn * 1000,
|
|
50
|
+
});
|
|
51
|
+
return responseBody.access_token;
|
|
52
|
+
}
|
|
4
53
|
class CippApi {
|
|
5
54
|
name = 'cippApi';
|
|
6
55
|
displayName = 'CIPP.app API';
|
|
7
56
|
icon = 'file:cipp.png';
|
|
8
57
|
documentationUrl = 'https://docs.cipp.app/api-documentation/setup-and-authentication';
|
|
58
|
+
genericAuth = true;
|
|
9
59
|
properties = [
|
|
10
60
|
{
|
|
11
61
|
displayName: 'CIPP Instance URL',
|
|
@@ -44,6 +94,15 @@ class CippApi {
|
|
|
44
94
|
description: 'The Client Secret from your CIPP-SAM Azure AD App Registration',
|
|
45
95
|
},
|
|
46
96
|
];
|
|
97
|
+
async authenticate(credentials, requestOptions) {
|
|
98
|
+
const accessToken = await getAccessToken(credentials);
|
|
99
|
+
requestOptions.headers = {
|
|
100
|
+
...(requestOptions.headers ?? {}),
|
|
101
|
+
Authorization: `Bearer ${accessToken}`,
|
|
102
|
+
Accept: 'application/json',
|
|
103
|
+
};
|
|
104
|
+
return requestOptions;
|
|
105
|
+
}
|
|
47
106
|
}
|
|
48
107
|
exports.CippApi = CippApi;
|
|
49
108
|
//# sourceMappingURL=CippApi.credentials.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CippApi.credentials.js","sourceRoot":"","sources":["../../credentials/CippApi.credentials.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"CippApi.credentials.js","sourceRoot":"","sources":["../../credentials/CippApi.credentials.ts"],"names":[],"mappings":";;;AAcA,MAAM,UAAU,GAAG,IAAI,GAAG,EAA0B,CAAC;AAErD,SAAS,mBAAm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