MASTER feat(Docuware): refs #8066 use oath #3084

Merged
alexm merged 7 commits from 8066-docuware_oauth into master 2024-10-17 07:09:08 +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
*
* @param {string} cookie - The docuware cookie
* @return {object} - The headers
*/
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: {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',
scope: 'docuware.platform',
client_id: 'docuware.platform.net.client',
username,
password
}));
console.log('data: ', data);
}, {headers: {
'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 = {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'access_token': access_token
'Authorization': token
}
};
return {
url: docuwareConfig.url,
url,
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 fileCabinets = fileCabinetResponse.data.FileCabinet;
const fileCabinetId = fileCabinets.find(fileCabinet => fileCabinet.Name === docuwareInfo.fileCabinetName).Id;

View File

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

View File

@ -16,7 +16,7 @@
"url": {
"type": "string"
},
"cookie": {
"token": {
"type": "string"
},
"username": {
@ -24,6 +24,9 @@
},
"password": {
"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 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;