Skip to content

Commit 3549c99

Browse files
committed
Obtain access token from yepcode api instead of keycloak
1 parent abdd2ff commit 3549c99

File tree

2 files changed

+7
-41
lines changed

2 files changed

+7
-41
lines changed

nodes/YepCode/transport/base64Utils.ts

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,5 @@
11
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
22

3-
export function base64Encode(str: string): string {
4-
// Convert string to UTF-8 bytes
5-
const bytes: number[] = [];
6-
for (let i = 0; i < str.length; i++) {
7-
let code = str.charCodeAt(i);
8-
if (code < 0x80) {
9-
bytes.push(code);
10-
} else if (code < 0x800) {
11-
bytes.push(0xc0 | (code >> 6));
12-
bytes.push(0x80 | (code & 0x3f));
13-
} else if (code < 0x10000) {
14-
bytes.push(0xe0 | (code >> 12));
15-
bytes.push(0x80 | ((code >> 6) & 0x3f));
16-
bytes.push(0x80 | (code & 0x3f));
17-
}
18-
}
19-
20-
let encoded = '';
21-
for (let i = 0; i < bytes.length; i += 3) {
22-
const b1 = bytes[i];
23-
const b2 = i + 1 < bytes.length ? bytes[i + 1] : 0;
24-
const b3 = i + 2 < bytes.length ? bytes[i + 2] : 0;
25-
26-
const triplet = (b1 << 16) | (b2 << 8) | b3;
27-
28-
encoded += chars[(triplet >> 18) & 0x3f];
29-
encoded += chars[(triplet >> 12) & 0x3f];
30-
encoded += i + 1 < bytes.length ? chars[(triplet >> 6) & 0x3f] : '=';
31-
encoded += i + 2 < bytes.length ? chars[triplet & 0x3f] : '=';
32-
}
33-
34-
return encoded;
35-
}
36-
373
export function base64Decode(str: string): string {
384
// Remove any padding
395
str = str.replace(/=+$/, '');

nodes/YepCode/transport/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
IHttpRequestMethods,
66
IDataObject,
77
} from 'n8n-workflow';
8-
import { base64Decode, base64Encode } from './base64Utils';
8+
import { base64Decode } from './base64Utils';
99

1010
export const DEFAULT_API_HOST = 'https://cloud.yepcode.io';
1111

@@ -21,19 +21,19 @@ export async function getYepCodeCredentials(
2121
};
2222
}
2323

24-
export async function obtainAccessToken(
24+
async function obtainAccessToken(
2525
this: IExecuteFunctions | ILoadOptionsFunctions,
2626
apiHost: string,
27-
clientId: string,
28-
clientSecret: string,
27+
teamId: string,
28+
apiToken: string,
2929
): Promise<string> {
3030
try {
3131
const options: IHttpRequestOptions = {
3232
method: 'POST',
33-
url: `${apiHost}/auth/realms/yepcode/protocol/openid-connect/token`,
33+
url: `${apiHost}/api/${teamId}/rest/auth/token`,
3434
headers: {
3535
'Content-Type': 'application/x-www-form-urlencoded',
36-
authorization: `Basic ${base64Encode(`${clientId}:${clientSecret}`)}`,
36+
'x-api-token': apiToken,
3737
},
3838
body: 'grant_type=client_credentials',
3939
};
@@ -82,7 +82,7 @@ export async function apiRequest(
8282
throw new Error('Invalid clientId format: ' + clientId);
8383
}
8484

85-
const accessToken = await obtainAccessToken.call(this, apiHost, clientId, clientSecret);
85+
const accessToken = await obtainAccessToken.call(this, apiHost, teamId, apiToken);
8686
const options: IHttpRequestOptions = {
8787
method,
8888
url: `${apiHost}/api/${teamId}/rest/${endpoint}`,

0 commit comments

Comments
 (0)