@@ -6,16 +6,25 @@ export const TOKEN_FILE = process.cwd() + '/../token.txt'
66export const APP_ID_FILE = process . cwd ( ) + '/../app_id.txt'
77export const APP_SECRET_FILE = process . cwd ( ) + '/../app_secret.txt'
88export const FIREWALL_DEFAULTS_FILE = process . cwd ( ) + '/../firewall_defaults.json'
9+ export const UUID_FILE = process . cwd ( ) + '/../uuid.txt'
910
1011const fs = require ( 'fs' ) ;
1112
1213export 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