Permalink
Browse files

Fixed auth references. Fixes #5.

  • Loading branch information...
1 parent dd17fec commit f1e9a6f92dc3611f16704b152974b5b62e55054d Christian Wesselhoeft committed Mar 11, 2013
Showing with 16 additions and 12 deletions.
  1. +8 −1 README.md
  2. +4 −4 index.js
  3. +1 −1 tests/get.test.js
  4. +2 −4 tests/utils.test.js
  5. +1 −2 utils.js
View
@@ -160,9 +160,16 @@ Note: `id` and `name` are not used by these methods.
***
### Properties
-#### publicKey, privateKey
+#### auth.publicKey, auth.privateKey
Keys to use for generating an authorization header.
+ var armory = require('armory')
+
+ armory.auth.publicKey = 'foo'
+ armory.auth.privateKey = 'bar'
+
+ armory.realmStatus(function() { ... })
+
### Notes on usage:
* If an error occurs (including API errors), it will be passed as an Error object to the first parameter of the callback with its message in the `message` property. Otherwise, the parsed response body will passed as the second parameter and the full response will be passed as the third parameter.
View
@@ -3,7 +3,7 @@ var request = require('request')
, url = require('url')
, utils = require('./utils')
-var armory = { privateKey: null, publicKey: null }
+var armory = { auth: { privateKey: null, publicKey: null } }
// Makes the request.
armory._get = function(path, options, callback) {
@@ -24,14 +24,14 @@ armory._get = function(path, options, callback) {
})
// Authentication
- if (this.privateKey && this.publicKey) {
- var signature = crypto.createHmac('sha1', this.privateKey)
+ if (this.auth.privateKey && this.auth.publicKey) {
+ var signature = crypto.createHmac('sha1', this.auth.privateKey)
, date = new Date().toUTCString()
signature.update(['GET', date, path].join('\n') + '\n')
options.headers['Date'] = date
- options.headers['Authorization'] = 'BNET ' + this.publicKey + ':' +
+ options.headers['Authorization'] = 'BNET ' + this.auth.publicKey + ':' +
signature.digest('base64')
}
View
@@ -41,7 +41,7 @@ test('should return Stream if no callback is passed', function(t) {
})
test('auth', function(t) {
- armory.privateKey = armory.publicKey = 'test'
+ armory.auth.privateKey = armory.auth.publicKey = 'test'
armory._get('/realm/status', options, function(err, body, res) {
var time = new Date(res.req.getHeader('Date')).getTime()
View
@@ -14,8 +14,7 @@ test('getKey', function(t) {
test('wrap', function(t) {
var obj =
- { privateKey: 1
- , publicKey: 1
+ { auth: { privateKey: 0, publicKey: 0 }
, defaults: 1
, _get: 1
, key: 1
@@ -25,8 +24,7 @@ test('wrap', function(t) {
, wrapped = utils.wrap(obj, wrapper)
t.equal(wrapped.key, 2, 'got key with wrapper applied')
- t.equal(wrapped.privateKey, 1, 'privateKey excluded from wrapper')
- t.equal(wrapped.publicKey, 1, 'publicKey excluded from wrapper')
+ t.equal(wrapped.auth, obj.auth, 'auth excluded from wrapper')
t.equal(wrapped.defaults, 1, 'defaults excluded from wrapper')
t.equal(wrapped._get, 1, '_get excluded from wrapper')
View
@@ -10,8 +10,7 @@ exports.getKey = function (obj, key) {
// Returns a new instance of the module with a wrapper applied.
exports.wrap = function(target, wrapper) {
var wrapped =
- { privateKey: target.privateKey
- , publicKey: target.publicKey
+ { auth: target.auth
, defaults: target.defaults
, _get: target._get
}

0 comments on commit f1e9a6f

Please sign in to comment.