inorganik / digest-auth-request

Make digest-auth requests with vanilla javascript
MIT License
70 stars 49 forks source link

Unexpected char 0x0a at XX in authorization value #33

Open bartoszwolski opened 6 years ago

bartoszwolski commented 6 years ago

I had an issue with this, and found out each headers value should be trimmed.

Its simple one line fix, adding ' val = val.trim();'

for (var i = 0; i < digestHeaders.length; i++) {
    var equalIndex = digestHeaders[i].indexOf('='),
        key = digestHeaders[i].substring(0, equalIndex),
        val = digestHeaders[i].substring(equalIndex + 1);
    val = val.replace(/['"]+/g, '');
    val = val.trim();
    // find realm
    if (key.match(/realm/i) != null) {
        self.realm = val;
    }
    // find nonce
    if (key.match(/nonce/i) != null) {
        self.nonce = val;
    }
    // find opaque
    if (key.match(/opaque/i) != null) {
        self.opaque = val;
    }
    // find QOP
    if (key.match(/qop/i) != null) {
        self.qop = val;
    }
}

inside this for loop

@inorganik correct me if I am wrong since I am super fresh in JS and RN, but this seems to fix an issue without breaking anything.