Skip to content

Commit 3991034

Browse files
authored
Merge pull request #4 from luckymarmot/fix-issue
Fix challenge request
2 parents 1378bd0 + 7e5ebb9 commit 3991034

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

src/DigestAuthDynamicValue.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,21 @@ class DigestAuthDynamicValue {
77
static help = 'https://luckymarmot.com/paw/doc/auth/digest-auth'
88
static inputs = [
99
DynamicValueInput('username', 'Username', "String"),
10-
DynamicValueInput('password', 'Password', "SecureValue")
10+
DynamicValueInput('password', 'Password', "SecureValue"),
11+
DynamicValueInput('include_body', 'Include body in challenge',
12+
"Checkbox", {defaultValue: false}
13+
)
1114
]
1215

1316
evaluate(context) {
1417
if (context.runtimeInfo.task != 'requestSend') {
1518
return '** digest is only generated during request send **'
1619
}
17-
const dauth = new HTTPDigestAuth(this.username, this.password)
20+
const dauth = new HTTPDigestAuth(
21+
this.username,
22+
this.password,
23+
this.include_body
24+
)
1825
dauth.getChallenge(context)
1926
return dauth.build_digest_header()
2027
}

src/HTTPDigestAuth.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import Immutable from 'immutable'
33
export default class HTTPDigestAuth {
44

55
// Attaches HTTP Digest Authentication to the given Request object.
6-
constructor(username, password) {
6+
constructor(username, password, include_body=false) {
77
this.username = username
88
this.password = password
9+
this.include_body = include_body
910
//# Keep state in per-thread local storage
1011
this._thread_local = {}
1112
this.init_state()
@@ -46,6 +47,18 @@ export default class HTTPDigestAuth {
4647
currentUserAgent = "Paw/" + bundle.appVersion + " (Macintosh; OS X/" + bundle.osVersion + ") GCDHTTPRequest"
4748
}
4849
request.setRequestHeader('User-Agent', currentUserAgent)
50+
let headers = Immutable.fromJS(currentRequest.headers)
51+
headers.forEach(
52+
(header_value, key) => {
53+
if (key.toLowerCase() !== 'authorization') {
54+
// do not add the auth header
55+
request.setRequestHeader(key, header_value)
56+
}
57+
}
58+
)
59+
if (this.include_body) {
60+
request.requestBody = currentRequest.body
61+
}
4962
request.send()
5063
const WWWAuthenticate = request.getResponseHeader('WWW-Authenticate')
5164
Immutable.Map(RE).forEach( (re, key) => {

0 commit comments

Comments
 (0)