Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@
* Copyright (c) 2014, Joyent, Inc.
*/

module.exports = require('./lib/client.js');
var client = require('./lib/client.js');
var scopeSchema = require('./lib/scope-schema.js');
Comment thread
danmcd marked this conversation as resolved.

client.scopeSchema = scopeSchema;

module.exports = client;
23 changes: 11 additions & 12 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ MahiClient.prototype.getLookup = function getLookup(opts, cb) {
*
* accessKeyId: AWS access key ID (e.g., "AKIA123456789EXAMPLE")
* cb: callback in the form fn(err, userInfo)
*
*
* Returns user object without access key secrets:
* {
* type: "account",
Expand All @@ -811,14 +811,14 @@ MahiClient.prototype.getLookup = function getLookup(opts, cb) {
* AccessKeyNotFoundError
* RedisError
*/
MahiClient.prototype.getUserByAccessKey = function
MahiClient.prototype.getUserByAccessKey = function
getUserByAccessKey(accessKeyId, cb) {
assert.string(accessKeyId, 'accessKeyId');
assert.func(cb, 'callback');

var self = this;
var path = sprintf('/aws-auth/%s', accessKeyId);

self.http.get(path, function (err, req, res, obj) {
if (err) {
cb(err);
Expand All @@ -831,42 +831,41 @@ MahiClient.prototype.getUserByAccessKey = function

/**
* Verify AWS Signature Version 4 authentication
*
*
* request: HTTP request object with AWS4-HMAC-SHA256 authorization header
* cb: callback in the form fn(err, result)
*
* Returns:
* {
* valid: true,
* accessKeyId: "AKIA123456789EXAMPLE",
* accessKeyId: "AKIA123456789EXAMPLE",
* userUuid: "user-uuid"
* }
*
* errors:
* InvalidSignatureError
* AccessKeyNotFoundError
* AccessKeyNotFoundError
* RequestTimeTooSkewedError
*/
MahiClient.prototype.verifySigV4 = function verifySigV4(request, cb) {
assert.object(request, 'request');
assert.func(cb, 'callback');

var self = this;

// Forward the original headers to mahi for SigV4 verification
var requestOptions = {
path: '/aws-verify',
headers: request.headers
};

// Add request method and URL as query parameters since mahi needs them for verification
var qs = require('querystring');

/* Add method and URL as query parameters for mahi verification */
var queryParams = {
method: request.method,
url: request.url
};
requestOptions.path += '?' + qs.stringify(queryParams);

self.http.post(requestOptions, {}, function (err, req, res, obj) {
if (err) {
cb(err);
Expand Down
Loading