master #3125

Merged
alexm merged 13 commits from master into test 2024-10-18 05:09:33 +00:00
4 changed files with 35 additions and 16 deletions
Showing only changes of commit 3c881d5e48 - Show all commits

View File

@ -4,32 +4,45 @@ module.exports = Self => {
/** /**
* Returns basic headers * Returns basic headers
* *
* @param {string} cookie - The docuware cookie
* @return {object} - The headers * @return {object} - The headers
*/ */
Self.getOptions = async() => { Self.getOptions = async() => {
const {url, username, password} = await Self.app.models.DocuwareConfig.findOne(); const docuwareConfig = await Self.app.models.DocuwareConfig.findOne();
const now = new Date().getTime();
let {url, username, password, token, expired} = docuwareConfig;
if (!expired || expired < now + 60) {
const {data: {IdentityServiceUrl}} = await axios.get(`${url}/Home/IdentityServiceInfo`); const {data: {IdentityServiceUrl}} = await axios.get(`${url}/Home/IdentityServiceInfo`);
const {data: {token_endpoint}} = await axios.get(`${IdentityServiceUrl}/.well-known/openid-configuration`); const {data: {token_endpoint}} = await axios.get(`${IdentityServiceUrl}/.well-known/openid-configuration`);
const data = await axios.post(token_endpoint, JSON.stringify({ const {data} = await axios.post(token_endpoint, {
grant_type: 'password', grant_type: 'password',
scope: 'docuware.platform', scope: 'docuware.platform',
client_id: 'docuware.platform.net.client', client_id: 'docuware.platform.net.client',
username, username,
password password
})); }, {headers: {
console.log('data: ', data); 'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded'
}});
const newToken = data.access_token;
token = data.token_type + ' ' + newToken;
await docuwareConfig.updateAttributes({
token,
expired: now + data.expires_in
});
}
const headers = { const headers = {
headers: { headers: {
'Accept': 'application/json', 'Accept': 'application/json',
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'access_token': access_token 'Authorization': token
} }
}; };
return { return {
url: docuwareConfig.url, url,
headers headers
}; };
}; };
@ -80,6 +93,7 @@ module.exports = Self => {
} }
}); });
console.log('options.headers: ', options.headers);
const fileCabinetResponse = await axios.get(`${options.url}/FileCabinets`, options.headers); const fileCabinetResponse = await axios.get(`${options.url}/FileCabinets`, options.headers);
const fileCabinets = fileCabinetResponse.data.FileCabinet; const fileCabinets = fileCabinetResponse.data.FileCabinet;
const fileCabinetId = fileCabinets.find(fileCabinet => fileCabinet.Name === docuwareInfo.fileCabinetName).Id; const fileCabinetId = fileCabinets.find(fileCabinet => fileCabinet.Name === docuwareInfo.fileCabinetName).Id;

View File

@ -143,7 +143,7 @@ module.exports = Self => {
headers: { headers: {
'Content-Type': 'multipart/form-data', 'Content-Type': 'multipart/form-data',
'X-File-ModifiedDate': Date.vnNew(), 'X-File-ModifiedDate': Date.vnNew(),
'Cookie': docuwareOptions.headers.headers.Cookie, 'Authorization': docuwareOptions.headers.headers.Authorization,
...data.getHeaders() ...data.getHeaders()
}, },
}; };

View File

@ -16,7 +16,7 @@
"url": { "url": {
"type": "string" "type": "string"
}, },
"cookie": { "token": {
"type": "string" "type": "string"
}, },
"username": { "username": {
@ -24,6 +24,9 @@
}, },
"password": { "password": {
"type": "string" "type": "string"
},
"expired":{
"type": "number"
} }
} }
} }

View File

@ -1,2 +1,4 @@
ALTER TABLE vn.docuwareConfig ADD IF NOT EXISTS username varchar(100) NULL; ALTER TABLE vn.docuwareConfig ADD IF NOT EXISTS username varchar(100) NULL;
ALTER TABLE vn.docuwareConfig ADD IF NOT EXISTS password varchar(100) NULL; ALTER TABLE vn.docuwareConfig ADD IF NOT EXISTS password varchar(100) NULL;
ALTER TABLE vn.docuwareConfig ADD IF NOT EXISTS token text NULL;
ALTER TABLE vn.docuwareConfig ADD IF NOT EXISTS expired int(11) NULL;