From 008b27eb0f5aea72ec53b8dc10fd03c66ef894a3 Mon Sep 17 00:00:00 2001 From: Vitalii Date: Thu, 21 Jun 2018 11:57:32 +0300 Subject: [PATCH] bug #14 fixed (#17) "opaque" field should not be specified if server did not provide it --- digestAuth.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/digestAuth.go b/digestAuth.go index 868a2c6..dbf8660 100644 --- a/digestAuth.go +++ b/digestAuth.go @@ -77,7 +77,12 @@ func getDigestAuthorization(digestParts map[string]string) string { nonceCount := 00000001 cnonce := getCnonce() response := getMD5(fmt.Sprintf("%s:%s:%v:%s:%s:%s", ha1, d["nonce"], nonceCount, cnonce, d["qop"], ha2)) - authorization := fmt.Sprintf(`Digest username="%s", realm="%s", nonce="%s", uri="%s", cnonce="%s", nc="%v", qop="%s", response="%s", opaque="%s"`, - d["username"], d["realm"], d["nonce"], d["uri"], cnonce, nonceCount, d["qop"], response, d["opaque"]) + authorization := fmt.Sprintf(`Digest username="%s", realm="%s", nonce="%s", uri="%s", qop=%s, nc=%v, cnonce="%s", response="%s"`, + d["username"], d["realm"], d["nonce"], d["uri"], d["qop"], nonceCount, cnonce, response) + + if d["opaque"] != "" { + authorization += fmt.Sprintf(`, opaque="%s"`, d["opaque"]) + } + return authorization }