@@ -23,6 +23,8 @@ import {HttpCookieAgent} from "http-cookie-agent/http";
2323import { Agent as HttpAgent } from "node:http" ;
2424import { Agent as HttpsAgent } from "node:https" ;
2525import * as crypto from "crypto" ;
26+ import { jwtDecode } from "jwt-decode" ;
27+ import { Jwt } from "./interfaces/librelink/jwt" ;
2628
2729// Generate new Ciphers for stealth mode in order to bypass SSL fingerprinting used by Cloudflare.
2830// The new Ciphers are then used in the HTTPS Agent for Axios.
@@ -95,7 +97,8 @@ const libreLinkUpHttpHeaders: LibreLinkUpHttpHeaders = {
9597 "User-Agent" : USER_AGENT ,
9698 "Content-Type" : "application/json;charset=UTF-8" ,
9799 "version" : LIBRE_LINK_UP_VERSION ,
98- "product" : LIBRE_LINK_UP_PRODUCT
100+ "product" : LIBRE_LINK_UP_PRODUCT ,
101+ "account-id" : "" ,
99102}
100103
101104if ( config . singleShot )
@@ -141,7 +144,7 @@ async function main(): Promise<void>
141144export async function login ( ) : Promise < AuthTicket | null >
142145{
143146 config = readConfig ( )
144-
147+
145148 try
146149 {
147150 const url = "https://" + LIBRE_LINK_UP_URL + "/llu/auth/login"
@@ -353,6 +356,19 @@ function getLluAuthHeaders(): LibreLinkUpHttpHeaders
353356{
354357 const authenticatedHttpHeaders = libreLinkUpHttpHeaders ;
355358 authenticatedHttpHeaders . Authorization = "Bearer " + getAuthenticationToken ( ) ;
359+
360+ if ( authTicket )
361+ {
362+ try
363+ {
364+ let jwt : Jwt = jwtDecode ( authTicket . token ) ;
365+ let hashedAccountId : string = crypto . createHash ( "sha256" ) . update ( jwt . id ) . digest ( "hex" ) ;
366+ authenticatedHttpHeaders [ "account-id" ] = hashedAccountId ;
367+ } catch ( error )
368+ {
369+ logger . error ( "Error getting accountId: " , error ) ;
370+ }
371+ }
356372 logger . debug ( "authenticatedHttpHeaders: " + JSON . stringify ( authenticatedHttpHeaders ) ) ;
357373 return authenticatedHttpHeaders ;
358374}
0 commit comments