Skip to content

Commit

Permalink
Merge pull request #4 from luckymarmot/fix-issue
Browse files Browse the repository at this point in the history
Fix challenge request
  • Loading branch information
hishnash committed Mar 3, 2017
2 parents 1378bd0 + 7e5ebb9 commit 3991034
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/DigestAuthDynamicValue.js
Expand Up @@ -7,14 +7,21 @@ class DigestAuthDynamicValue {
static help = 'https://luckymarmot.com/paw/doc/auth/digest-auth'
static inputs = [
DynamicValueInput('username', 'Username', "String"),
DynamicValueInput('password', 'Password', "SecureValue")
DynamicValueInput('password', 'Password', "SecureValue"),
DynamicValueInput('include_body', 'Include body in challenge',
"Checkbox", {defaultValue: false}
)
]

evaluate(context) {
if (context.runtimeInfo.task != 'requestSend') {
return '** digest is only generated during request send **'
}
const dauth = new HTTPDigestAuth(this.username, this.password)
const dauth = new HTTPDigestAuth(
this.username,
this.password,
this.include_body
)
dauth.getChallenge(context)
return dauth.build_digest_header()
}
Expand Down
15 changes: 14 additions & 1 deletion src/HTTPDigestAuth.js
Expand Up @@ -3,9 +3,10 @@ import Immutable from 'immutable'
export default class HTTPDigestAuth {

// Attaches HTTP Digest Authentication to the given Request object.
constructor(username, password) {
constructor(username, password, include_body=false) {
this.username = username
this.password = password
this.include_body = include_body
//# Keep state in per-thread local storage
this._thread_local = {}
this.init_state()
Expand Down Expand Up @@ -46,6 +47,18 @@ export default class HTTPDigestAuth {
currentUserAgent = "Paw/" + bundle.appVersion + " (Macintosh; OS X/" + bundle.osVersion + ") GCDHTTPRequest"
}
request.setRequestHeader('User-Agent', currentUserAgent)
let headers = Immutable.fromJS(currentRequest.headers)
headers.forEach(
(header_value, key) => {
if (key.toLowerCase() !== 'authorization') {
// do not add the auth header
request.setRequestHeader(key, header_value)
}
}
)
if (this.include_body) {
request.requestBody = currentRequest.body
}
request.send()
const WWWAuthenticate = request.getResponseHeader('WWW-Authenticate')
Immutable.Map(RE).forEach( (re, key) => {
Expand Down

0 comments on commit 3991034

Please sign in to comment.