Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I am using onlyoffice with react. While opening my word file(docx file) i get the error “The document security token is not correctly formed. Please contact your Document Server administrator.” #705

Open
viscous-coder opened this issue Jun 28, 2024 · 3 comments

Comments

@viscous-coder
Copy link

import React, { useState, useEffect } from “react”;
import { DocumentEditor } from “@onlyoffice/document-editor-react”;

const OnlyOffc = (props) => {
const [docUrl, setDocUrl] = useState(“”);
let token = sessionStorage.getItem(“jwt_token”);
let username = localStorage.getItem(“username”);
let deptRole = sessionStorage.getItem(“role”);
let sessionId = sessionStorage.getItem(“sessionId”);
console.log(props.url, token, “this”);
let correctUrl = props?.url?.replaceAll(“xxxyyyzzz”, “/”);

const onDocumentReady = () => {
console.log(“Document is loaded”);
setLoading(false);
};

const onLoadComponentError = function (errorCode, errorDescription) {
switch (errorCode) {
case -1: // Unknown error loading component
console.log(errorDescription);
break;

case -2: // Error load DocsAPI from http://documentserver/
console.log(errorDescription);
break;

case -3: // DocsAPI is not defined
console.log(errorDescription);
break;
}
};

useEffect(() => {
fetch(For_Getting_the_file_url, { //to get the file url
headers: {
“Content-Type”: “application/json”,
Authorization: "Bearer " + token,
username: username,
deptRole: deptRole,
sessionId: sessionId,
},
})
.then(async (res) => {
console.log(res, “res”);
let data = await res.blob();
// console.log(data);

let file = new File([data], "test.docx");
console.log("file", file.name);

setDocUrl(URL.createObjectURL(file)); // set object URL of file as docUrl

})
.catch((error) => {
console.log(error);
});
}, [correctUrl, token, username, deptRole, sessionId]);

console.log(“docurl”, docUrl);

return (

{docUrl && (
<DocumentEditor
id=“docxEditor”
documentServerUrl=“DOCKER_URL” //getting from docker
config={{
document: {
key: “SECRET_KEY”,
fileType: “docx”,
title: “farmer.docx”,
url: docUrl,
},
documentType: “word”,
type: “desktop”,
height: “800px”,
width: “100%”,
}}
events_onDocumentReady={onDocumentReady}
onLoadComponentError={onLoadComponentError}
/>
)}

);
};
export default OnlyOffc;

//local.json
{
“services”: {
“CoAuthoring”: {
“sql”: {
…data
},
“token”: {
“enable”: {
“request”: {
“inbox”: true,
“outbox”: true,
},
“browser”: true
},
“inbox”: {
“header”: “Authorization”,
“inBody”: false
},
“outbox”: {
“header”: “Authorization”,
“inBody”: false
}
},
“secret”: {
“inbox”: {
“string”: “SECRET_KEY”
},
“outbox”: {
“string”: “SECRET_KEY”
},
“session”: {
“string”: “SECRET_KEY”
}
}
}
},
“rabbitmq”: {
“url”: “Some_URL”
},
“wopi”: {
“enable”: false,
“privateKey”: “SOMEVALUES”,
“privateKeyOld”: “SOMEVALUES”,
“publicKey”: “SOMEVALUES”,
“publicKeyOld”: “SOMEVALUES”,
“modulus”: “SOMEVALUES”,
“modulusOld”: “SOMEVALUES”,
“exponent”: 12333,
“exponentOld”: 11111
},
“queue”: {
“type”: “abc”
},
“storage”: {
“fs”: {
“secretString”: “MY_SECRET_KEY”
}
}
}

//compose.yml

environment:
- JWT_ENABLED=true
- JWT_SECRET=SECRET_KEY
- JWT_HEADER=Authorization
how to resolve that error

@bjornclauw
Copy link

In my case, Filestash connects to onlyoffice through the docker network, here is a basic compose file with ENV vars that work for me

services:
  app:
    container_name: filestash
    image: machines/filestash
    restart: always
    environment:
      - APPLICATION_URL=
      - GDRIVE_CLIENT_ID=<gdrive_client>
      - GDRIVE_CLIENT_SECRET=<gdrive_secret>
      - DROPBOX_CLIENT_ID=<dropbox_key>
      - ONLYOFFICE_URL=http://onlyoffice
    ports:
      - 8334:8334
    volumes:
      - /mnt/data/filestash:/app/data/state/
  onlyoffice:
    container_name: filestash_oods
    image: onlyoffice/documentserver
    restart: always
    security_opt:
      - seccomp:unconfined
    environment:
      JWT_ENABLED: "false"
      ALLOW_META_IP_ADDRESS: "true"
      ALLOW_PRIVATE_IP_ADDRESS: "true"```

@viscous-coder
Copy link
Author

Thanks for reply @bjornclauw, could you please check it ONLYOFFICE/DocumentServer#2781 here also. I solve the token problem but now i get the issue "Javascript isn't enable in your browser"

@Anisha12311
Copy link

The message "Javascript isn't enabled in your browser" appeared to me as well. Is there a way to solve this?

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants