From a8ee773a39d4dce1258940a5322f79454dd7c115 Mon Sep 17 00:00:00 2001 From: Zaid Abdulla Date: Thu, 12 Sep 2013 08:56:12 +0300 Subject: [PATCH] Minor cleanup on connection request authentication code. --- api-functions.coffee | 9 +++++---- auth.coffee | 5 +++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/api-functions.coffee b/api-functions.coffee index 7bfc831..8c39115 100644 --- a/api-functions.coffee +++ b/api-functions.coffee @@ -9,11 +9,12 @@ auth = require './auth' connectionRequest = (deviceId, callback) -> conReq = (url, authString, callback) -> - if authString - url = URL.parse(url) - url.headers = {'Authorization' : authString} + options = URL.parse(url) - request = http.get(url, (res) -> + if authString + options.headers = {'Authorization' : authString} + + request = http.get(options, (res) -> if res.statusCode == 401 authHeader = auth.parseAuthHeader(res.headers['www-authenticate']) callback(res.statusCode, authHeader) diff --git a/auth.coffee b/auth.coffee index b547030..d7b1316 100644 --- a/auth.coffee +++ b/auth.coffee @@ -54,8 +54,9 @@ exports.digest = (username, password, uri, httpMethod, body, authHeader) -> authString += ",realm=\"#{authHeader.realm}\"" authString += ",nonce=\"#{authHeader.nonce}\"" authString += ",uri=\"#{uri}\"" - authString += ",qop=\"#{qop}\"" - authString += ",nc=\"#{nc}\"" + authString += ",algorithm=#{authHeader.algorithm}" if authHeader.algorithm? + authString += ",qop=#{qop}" + authString += ",nc=#{nc}" authString += ",cnonce=\"#{cnonce}\"" authString += ",response=\"#{response}\"" authString += ",opaque=\"#{authHeader.opaque}\""