@CyberGen
I leave this here cuz, nobody ELSE should spend a week of their lives figuring this out. 
The code below works for me doing the following.
User Authentication:
Set up credentials for JWT token generation and sent a POST request to the /wp-json/jwt-auth/v1/token endpoint to authenticate and receive a JWT.
Token Handling:
The received JWT is used for subsequent requests to ensure each request is authenticated.
Token Validation:
The token is validated by sending it back to the server, ensuring it's valid and active before proceeding with any sensitive operations.
License Activation:
Post-token validation, we proceed to activate the license using the license key and other necessary details, which are then verified by the server.
// Server Address
Server.setBaseURL("https://yourserver.com");
// Credentials for authentication
const var credentials =
{
"username": "you@yourserver.com",
"password": "yourpassword"
}
// Relevant references
const var authUrl = "/wp-json/jwt-auth/v1/token";
const var validateUrl = "/wp-json/jwt-auth/v1/token/validate";
const var activateUrl = "/wp-json/wclm/v3/activate";
reg jwtToken = "";
// Some debug stuff
Console.clear();
if (Server.isOnline()) Console.print("Server is Online!" + "\n");
Console.print("Authorization URL: " + authUrl);
Console.print("Validate URL: " + validateUrl);
Console.print("Activate URL: " + activateUrl + "\n");
// Authenticate and retrieve token
inline function authenticateUser()
{
Console.print("Starting authentication process...");
Server.callWithPOST(authUrl, credentials, printResponse);
};
inline function printResponse(status, response)
{
Console.print("Received response: " + JSON.stringify(response));
if (response.token != "")
{
jwtToken = response.token;
validateToken();
}
else
{
Console.print("Authentication failed: " + response.message);
}
};
// Validate the JWT token
inline function validateToken()
{
Console.print("atempting to validate");
if (jwtToken != "")
{
Server.setHttpHeader("Authorization: Bearer " + jwtToken);
Server.callWithPOST(validateUrl, {}, function(status, response)
{
Console.print("Validation response: " + JSON.stringify(response));
if (response.code == "jwt_auth_valid_token")
{
Console.print("Token is valid!");
activateLicense();
}
else
{
Console.print("Token validation failed: " + response.message);
}
});
}
else
{
Console.print("No JWT token found.");
}
}
// License activation details
const var licenseData =
{
"license_key": "your-prod-key-lic"
};
// Activate the license
inline function activateLicense()
{
Console.print("Starting license activation..." + licenseData.license_key);
// Set the Authorization header with the JWT token
Server.setHttpHeader("Authorization: Bearer " + jwtToken);
// Send the POST request to activate the license
Server.callWithPOST(activateUrl, licenseData, handleActivationResponse);
};
// Function to handle the response from license activation
inline function handleActivationResponse(status, response)
{
Console.print(response.signature);
if (response["response"]["result"] == "success")
{
Console.print(response["response"]["message"] + "!");
}
else
{
Console.print(response["response"]["message"] + "!");
}
};
// Example: Trigger authentication when a button is clicked
inline function onButton1Control(component, value)
{
if (value) authenticateUser();
}
Content.getComponent("Button1").setControlCallback(onButton1Control);