master #3125
|
@ -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 {data: {IdentityServiceUrl}} = await axios.get(`${url}/Home/IdentityServiceInfo`);
|
const now = new Date().getTime();
|
||||||
const {data: {token_endpoint}} = await axios.get(`${IdentityServiceUrl}/.well-known/openid-configuration`);
|
let {url, username, password, token, expired} = docuwareConfig;
|
||||||
const data = await axios.post(token_endpoint, JSON.stringify({
|
|
||||||
grant_type: 'password',
|
if (!expired || expired < now + 60) {
|
||||||
scope: 'docuware.platform',
|
const {data: {IdentityServiceUrl}} = await axios.get(`${url}/Home/IdentityServiceInfo`);
|
||||||
client_id: 'docuware.platform.net.client',
|
const {data: {token_endpoint}} = await axios.get(`${IdentityServiceUrl}/.well-known/openid-configuration`);
|
||||||
username,
|
const {data} = await axios.post(token_endpoint, {
|
||||||
password
|
grant_type: 'password',
|
||||||
}));
|
scope: 'docuware.platform',
|
||||||
console.log('data: ', data);
|
client_id: 'docuware.platform.net.client',
|
||||||
|
username,
|
||||||
|
password
|
||||||
|
}, {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 = {
|
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;
|
||||||
|
|
|
@ -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()
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue