Permalink
Browse files

Enable token (delegated) authentication

  • Loading branch information...
1 parent 6229cc1 commit b73e821f9bb6018c6d47b7c4871107a12f51ed50 @JohnSonnenschein JohnSonnenschein committed Dec 12, 2012
Showing with 6 additions and 0 deletions.
  1. +6 −0 lib/cloudapi.js
View
@@ -128,6 +128,7 @@ function _encodeURI(path) {
* - {String} password (optional) login password.
* - {String} keyId (optional) SSH key id in cloudapi to sign with.
* - {String} key (optional) SSH key (PEM) that goes with `keyId`.
+ * - {String} token (optional) SSO token to sign in with.
* - {Boolean} noCache (optional) disable client caching (default false).
* - {Boolean} cacheSize (optional) number of cache entries (default 1k).
* - {Boolean} cacheExpiry (optional) entry age in seconds (default 60).
@@ -141,6 +142,8 @@ function CloudAPI(options) {
!(options.keyId && options.key))
throw new TypeError('Either username/password or ' +
'keyId/key are required');
+ if (options.token && !(options.keyId && options.key))
+ throw new TypeError('Token auth requires key/keyId');
if (options.logLevel)
log.level(options.logLevel);
@@ -163,6 +166,7 @@ function CloudAPI(options) {
this.keyId = options.keyId;
this.key = options.key;
this.sshAgent = options.sshAgent;
+ this.token = options.token;
} else {
this.basicAuth = true;
}
@@ -2096,6 +2100,8 @@ CloudAPI.prototype._request = function (path, body, callback) {
if (this.basicAuth) {
self.client.basicAuth(self.options.username, self.options.password);
} else {
+ if (this.token)
+ obj.headers["X-Auth-Token"] = this.token;
if (!this.sshAgent) {
var alg = / DSA /.test(this.key) ? 'DSA-SHA1' : 'RSA-SHA256';
var signer = crypto.createSign(alg);

0 comments on commit b73e821

Please sign in to comment.