Skip to content

Commit 15387b6

Browse files
committed
generate and save random UUID for the device
1 parent 87ae5fc commit 15387b6

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

client_common/src/auth.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,25 @@ export const TOKEN_FILE = process.cwd() + '/../token.txt'
66
export const APP_ID_FILE = process.cwd() + '/../app_id.txt'
77
export const APP_SECRET_FILE = process.cwd() + '/../app_secret.txt'
88
export const FIREWALL_DEFAULTS_FILE = process.cwd() + '/../firewall_defaults.json'
9+
export const UUID_FILE = process.cwd() + '/../uuid.txt'
910

1011
const fs = require('fs');
1112

1213
export class AuthHandler {
14+
private uuid: string
1315
private installation_code: string
1416
private client: AppGuardService
1517

1618
constructor(client: AppGuardService) {
1719
require('dotenv').config()
1820

21+
let uuid: string = fs.readFileSync(UUID_FILE, 'utf8');
22+
if (!uuid || uuid.trim() === '') {
23+
uuid = crypto.randomUUID();
24+
fs.writeFileSync(UUID_FILE, uuid, {flag: 'w'});
25+
}
26+
this.uuid = uuid.trim();
27+
1928
this.installation_code = process.env.INSTALLATION_CODE || ''
2029
this.client = client
2130

@@ -24,9 +33,8 @@ export class AuthHandler {
2433
}
2534

2635
async init(type: string){
27-
2836
let req: AuthorizationRequest = {
29-
uuid: "",
37+
uuid: this.uuid,
3038
code: this.installation_code,
3139
category: "AppGuard Client",
3240
targetOs: undefined,
@@ -36,7 +44,7 @@ export class AuthHandler {
3644
this.client.control_stream(req);
3745

3846
console.log("Waiting for the first server heartbeat...");
39-
while (this.token() === '') {
47+
while (this.token().trim() === '') {
4048
// sleep for 1 second
4149
await new Promise(resolve => setTimeout(resolve, 1000));
4250
}

0 commit comments

Comments
 (0)