Skip to content

Instantly share code, notes, and snippets.

@miton18
Last active August 25, 2021 10:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miton18/628d67dcb7cc65facef9833a348b4099 to your computer and use it in GitHub Desktop.
Save miton18/628d67dcb7cc65facef9833a348b4099 to your computer and use it in GitHub Desktop.
Postman OVH auth support
// environments to define
// endpoint -> https://api.ovh.com/1.0
// applicationKey
// applicationSecret
// consumerKey
// pre request script
pm.request.headers.add({
key: 'X-Ovh-Application',
value: pm.environment.get('applicationKey')
})
pm.request.headers.add({
key: 'X-Ovh-Consumer',
value: pm.environment.get('consumerKey')
})
function timeRelatedHeaders() {
var apiTimeDiff = pm.variables.get("apiTimeDiff")
var now = Math.round(Date.now()/1000) + apiTimeDiff
var toSign = pm.environment.get('applicationSecret') + '+' + pm.environment.get('consumerKey') + '+' + pm.request.method + '+' + pm.variables.replaceIn(pm.request.url.toString()) + '+' + (pm.request.body.toString() || '') + '+' + now;
var signature = '$1$' + CryptoJS.SHA1(toSign);
pm.request.headers.add({
key: 'X-Ovh-Signature',
value: signature
})
pm.request.headers.add({
key: 'X-Ovh-Timestamp',
value: now
})
}
if (!pm.collectionVariables.has('apiTimeDiff')) {
pm.sendRequest({
url: "https://api.ovh.com/1.0/auth/time",
method: "GET",
headers: {
'Content-Type': 'application/json; charset=utf-8'
},
body: {}
},
function (err, res) {
pm.expect(err).to.not.be.ok;
pm.expect(res).to.have.property('code', 200);
pm.expect(res).to.have.property('status', 'OK');
var serverTimestamp = res.text();
var apiTimeDiff = serverTimestamp - Math.round(Date.now()/1000);
pm.collectionVariables.set('apiTimeDiff', apiTimeDiff)
timeRelatedHeaders()
});
} else {
console.log('skipped')
timeRelatedHeaders()
}
console.debug(pm.request)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment