Skip to content

Commit

Permalink
Merge pull request #37 from scality/FT/authV4-2
Browse files Browse the repository at this point in the history
Implement authentication V4 signature verification route
  • Loading branch information
LaureVergeron committed Feb 16, 2016
2 parents 443a389 + 7049f99 commit 11c3176
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions lib/IAMClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,43 @@ class IAMClient {
this.request('GET', '/auth/v2', callback, data);
}

/**
* Verify AWS request signature using V4 auth (contrary to v2, hash is
* always sha256)
*
* @param {string} stringToSign - string to sign as built from the request
* @param {string} signature - the user-computed signature as provided by
* the request, base64-encoded
* @param {string} accessKey - the id of the key as provided by the request
* @param {string} region - the region where the user wants authentication
* @param {string} scopeDate - the date from which the signature is valid
* @param {string} [options.reqUid] - the request UID
* @param {IAMClient~requestCallback} callback - callback
* @returns {undefined}
*/
verifySignatureV4(stringToSign, signature, accessKey, region, scopeDate,
options, callback) {
assert(typeof stringToSign === 'string' && stringToSign !== '',
'stringToSign is required');
assert(typeof signature === 'string' && signature !== '',
'signature is required');
assert(typeof accessKey === 'string' && accessKey !== '',
'accessKey is required');
assert(typeof region === 'string' && region !== '',
'region is required');
assert(typeof scopeDate === 'string' && scopeDate !== '',
'scopeDate is required');
const data = { additionaldata: { stringToSign,
signatureFromRequest: signature,
accessKey,
region,
scopeDate } };
if (options.reqUid !== undefined) {
data[requestUidKey] = options.reqUid;
}
this.request('GET', '/auth/v4', callback, data);
}

/**
* @param {string} method - CRUD method chosen for the request
* @param {string} path - RESTful URL for the request
Expand Down

0 comments on commit 11c3176

Please sign in to comment.