Skip to content

Instantly share code, notes, and snippets.

@pbruna
Created August 10, 2023 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pbruna/c267c3cad430c058b6477d297c76ce06 to your computer and use it in GitHub Desktop.
Save pbruna/c267c3cad430c058b6477d297c76ce06 to your computer and use it in GitHub Desktop.
JWT for OnlyOffice
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/Javascript">
var editorConfig = {
"c": "add",
"images": [
{
"fileType": "png",
"url": "https://example.com/url-to-example-image.png"
}
]
}
function base64RemovePadding(str) {
return str.replace(/={1,2}$/, '');
}
function base64Encoder(text = "") {
return base64RemovePadding(window.btoa(text));
}
function generateJWT(config = {}, key = "")
{
var header = {
"alg": "HS256",
"typ": "JWT"
}
var payload = base64Encoder(JSON.stringify(header)) + "." + base64Encoder(JSON.stringify(config)) + "." + base64Encoder(key)
console.log(payload);
return(payload);
}
//generateJWT(editorConfig, "secret"))
</script>
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment