feat: onlyoffice jwt token support

This commit is contained in:
drosoCode 2023-04-02 19:34:25 +02:00
parent 7200a1ef62
commit 104872252d
10 changed files with 62 additions and 9 deletions

View File

@ -39,7 +39,10 @@ override the options.`,
DisableExternal: mustGetBool(flags, "branding.disableExternal"), DisableExternal: mustGetBool(flags, "branding.disableExternal"),
Files: mustGetString(flags, "branding.files"), Files: mustGetString(flags, "branding.files"),
}, },
OnlyOffice: "", OnlyOffice: settings.OnlyOffice{
URL: mustGetString(flags, "onlyoffice.url"),
JWTSecret: mustGetString(flags, "onlyoffice.jwtSecret"),
},
} }
ser := &settings.Server{ ser := &settings.Server{

View File

@ -55,8 +55,10 @@ you want to change. Other options will remain unchanged.`,
set.Branding.DisableExternal = mustGetBool(flags, flag.Name) set.Branding.DisableExternal = mustGetBool(flags, flag.Name)
case "branding.files": case "branding.files":
set.Branding.Files = mustGetString(flags, flag.Name) set.Branding.Files = mustGetString(flags, flag.Name)
case "onlyoffice": case "onlyoffice.url":
set.OnlyOffice = mustGetString(flags, flag.Name) set.OnlyOffice.URL = mustGetString(flags, flag.Name)
case "onlyoffice.jwtSecret":
set.OnlyOffice.JWTSecret = mustGetString(flags, flag.Name)
} }
}) })

View File

@ -12,6 +12,7 @@
"clipboard": "^2.0.4", "clipboard": "^2.0.4",
"core-js": "^3.9.1", "core-js": "^3.9.1",
"css-vars-ponyfill": "^2.4.3", "css-vars-ponyfill": "^2.4.3",
"jose": "^4.13.1",
"js-base64": "^2.5.1", "js-base64": "^2.5.1",
"lodash.clonedeep": "^4.5.0", "lodash.clonedeep": "^4.5.0",
"lodash.throttle": "^4.1.1", "lodash.throttle": "^4.1.1",
@ -8523,6 +8524,14 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/jose": {
"version": "4.13.1",
"resolved": "https://registry.npmjs.org/jose/-/jose-4.13.1.tgz",
"integrity": "sha512-MSJQC5vXco5Br38mzaQKiq9mwt7lwj2eXpgpRyQYNHYt2lq1PjkWa7DLXX0WVcQLE9HhMh3jPiufS7fhJf+CLQ==",
"funding": {
"url": "https://github.com/sponsors/panva"
}
},
"node_modules/js-base64": { "node_modules/js-base64": {
"version": "2.6.4", "version": "2.6.4",
"resolved": "https://registry.npmjs.org/js-base64/-/js-base64-2.6.4.tgz", "resolved": "https://registry.npmjs.org/js-base64/-/js-base64-2.6.4.tgz",
@ -16835,6 +16844,7 @@
"integrity": "sha512-8q67ORQ9O0Ms0nlqsXTVhaBefRBaLrzPxOewAZhdcO7onHwcO5/wRdWtHhZgfpCZlhY7NogkU16z3WnorSSkEA==", "integrity": "sha512-8q67ORQ9O0Ms0nlqsXTVhaBefRBaLrzPxOewAZhdcO7onHwcO5/wRdWtHhZgfpCZlhY7NogkU16z3WnorSSkEA==",
"dev": true, "dev": true,
"requires": { "requires": {
"@babel/core": "^7.11.0",
"@babel/helper-compilation-targets": "^7.9.6", "@babel/helper-compilation-targets": "^7.9.6",
"@babel/helper-module-imports": "^7.8.3", "@babel/helper-module-imports": "^7.8.3",
"@babel/plugin-proposal-class-properties": "^7.8.3", "@babel/plugin-proposal-class-properties": "^7.8.3",
@ -16847,6 +16857,7 @@
"@vue/babel-plugin-jsx": "^1.0.3", "@vue/babel-plugin-jsx": "^1.0.3",
"@vue/babel-preset-jsx": "^1.2.4", "@vue/babel-preset-jsx": "^1.2.4",
"babel-plugin-dynamic-import-node": "^2.3.3", "babel-plugin-dynamic-import-node": "^2.3.3",
"core-js": "^3.6.5",
"core-js-compat": "^3.6.5", "core-js-compat": "^3.6.5",
"semver": "^6.1.0" "semver": "^6.1.0"
} }
@ -22220,6 +22231,11 @@
} }
} }
}, },
"jose": {
"version": "4.13.1",
"resolved": "https://registry.npmjs.org/jose/-/jose-4.13.1.tgz",
"integrity": "sha512-MSJQC5vXco5Br38mzaQKiq9mwt7lwj2eXpgpRyQYNHYt2lq1PjkWa7DLXX0WVcQLE9HhMh3jPiufS7fhJf+CLQ=="
},
"js-base64": { "js-base64": {
"version": "2.6.4", "version": "2.6.4",
"resolved": "https://registry.npmjs.org/js-base64/-/js-base64-2.6.4.tgz", "resolved": "https://registry.npmjs.org/js-base64/-/js-base64-2.6.4.tgz",

View File

@ -14,6 +14,7 @@
"clipboard": "^2.0.4", "clipboard": "^2.0.4",
"core-js": "^3.9.1", "core-js": "^3.9.1",
"css-vars-ponyfill": "^2.4.3", "css-vars-ponyfill": "^2.4.3",
"jose": "^4.13.1",
"js-base64": "^2.5.1", "js-base64": "^2.5.1",
"lodash.clonedeep": "^4.5.0", "lodash.clonedeep": "^4.5.0",
"lodash.throttle": "^4.1.1", "lodash.throttle": "^4.1.1",

View File

@ -195,6 +195,7 @@
"newUser": "New User", "newUser": "New User",
"onlyOffice": "Only Office Integration", "onlyOffice": "Only Office Integration",
"onlyOfficeUrl": "Only Office URL (leave blank to disable)", "onlyOfficeUrl": "Only Office URL (leave blank to disable)",
"onlyOfficeJwtSecret": "Only Office JWT Secret (works only with https, leave blank to disable)",
"password": "Password", "password": "Password",
"passwordUpdated": "Password updated!", "passwordUpdated": "Password updated!",
"path": "Path", "path": "Path",

View File

@ -22,6 +22,7 @@
import { mapState } from "vuex"; import { mapState } from "vuex";
import url from "@/utils/url"; import url from "@/utils/url";
import { baseURL, onlyOffice } from "@/utils/constants"; import { baseURL, onlyOffice } from "@/utils/constants";
import * as jose from "jose";
import HeaderBar from "@/components/header/HeaderBar"; import HeaderBar from "@/components/header/HeaderBar";
import Action from "@/components/header/Action"; import Action from "@/components/header/Action";
@ -80,7 +81,7 @@ export default {
let onlyofficeScript = document.createElement("script"); let onlyofficeScript = document.createElement("script");
onlyofficeScript.setAttribute( onlyofficeScript.setAttribute(
"src", "src",
`${onlyOffice}/web-apps/apps/api/documents/api.js` `${onlyOffice.url}/web-apps/apps/api/documents/api.js`
); );
document.head.appendChild(onlyofficeScript); document.head.appendChild(onlyofficeScript);
@ -100,7 +101,7 @@ export default {
.replaceAll(/[!~[\]*'()/,;:\-%+. ]/g, "") .replaceAll(/[!~[\]*'()/,;:\-%+. ]/g, "")
).substring(0, 20); ).substring(0, 20);
let config = { const config = {
document: { document: {
fileType: this.req.extension.substring(1), fileType: this.req.extension.substring(1),
key: key, key: key,
@ -126,7 +127,18 @@ export default {
mode: this.user.perm.modify ? "edit" : "view" mode: this.user.perm.modify ? "edit" : "view"
} }
}; };
this.editor = new DocsAPI.DocEditor("editor", config);
if(onlyOffice.jwtSecret != "") {
const alg = 'HS256';
new jose.SignJWT(config)
.setProtectedHeader({ alg })
.sign(new TextEncoder().encode(onlyOffice.jwtSecret)).then((jwt) => {
config.token = jwt;
this.editor = new DocsAPI.DocEditor("editor", config);
})
} else {
this.editor = new DocsAPI.DocEditor("editor", config);
}
}; };
/*eslint-enable */ /*eslint-enable */
}, },

View File

@ -93,10 +93,21 @@
<input <input
class="input input--block" class="input input--block"
type="text" type="text"
v-model="settings.onlyoffice" v-model="settings.onlyoffice.url"
id="onlyoffice-url" id="onlyoffice-url"
/> />
</p> </p>
<p>
<label for="onlyoffice-jwt">{{
$t("settings.onlyOfficeJwtSecret")
}}</label>
<input
class="input input--block"
type="text"
v-model="settings.onlyoffice.jwtSecret"
id="onlyoffice-jwt"
/>
</p>
</div> </div>
<div class="card-action"> <div class="card-action">

View File

@ -16,7 +16,7 @@ type settingsData struct {
Branding settings.Branding `json:"branding"` Branding settings.Branding `json:"branding"`
Shell []string `json:"shell"` Shell []string `json:"shell"`
Commands map[string][]string `json:"commands"` Commands map[string][]string `json:"commands"`
OnlyOffice string `json:"onlyoffice"` OnlyOffice settings.OnlyOffice `json:"onlyoffice"`
} }
var settingsGetHandler = withAdmin(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) { var settingsGetHandler = withAdmin(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) {

7
settings/onlyoffice.go Normal file
View File

@ -0,0 +1,7 @@
package settings
// OnlyOffice contains the onlyoffice server connection settings of the app.
type OnlyOffice struct {
URL string `json:"url"`
JWTSecret string `json:"jwtSecret"`
}

View File

@ -21,7 +21,7 @@ type Settings struct {
Commands map[string][]string `json:"commands"` Commands map[string][]string `json:"commands"`
Shell []string `json:"shell"` Shell []string `json:"shell"`
Rules []rules.Rule `json:"rules"` Rules []rules.Rule `json:"rules"`
OnlyOffice string `json:"onlyoffice"` OnlyOffice OnlyOffice `json:"onlyoffice"`
} }
// GetRules implements rules.Provider. // GetRules implements rules.Provider.