• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Converting Base64 to Base64Url with only Javascript?

debian0001

Senior member
Hi,

I am utilizing ServiceNow JavaScript to try to convert Base64 to Base64Url. I cannot use any dependencies since it's all within ServiceNow tools.

I came up with this and it seems to work with all the tests I used. Is there any glaring problems?

GlideStringUtil.base64Encode is a native way in ServiceNow to convert to base64. Once I have that, I make an attempt to convert it to base64url so I can pass it to Azure DevOps.

var bodyBase64 = "This is a string to convert to base64!!!!!!"
var bodyBase64 = GlideStringUtil.base64Encode(body);

function convertobase64url(bodyBase64) {
//replace any instance of / with _
bodyBase64 = bodyBase64.replace("/", "_");
bodyBase64 = bodyBase64.replace("/+", "-");
bodyBase64 = bodyBase64.replaceAll("=", "");
return bodyBase64;
}
 
Back
Top