[TIMOB-24960] Android: TiHTTPClient credentials encoding issue.
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2017-07-18T22:30:17.000+0000 |
Affected Version/s | Release 6.1.1 |
Fix Version/s | Release 6.1.2 |
Components | Android |
Labels | n/a |
Reporter | Jorge Macias Garcia |
Assignee | Yordan Banev |
Created | 2017-07-14T14:44:21.000+0000 |
Updated | 2017-07-21T17:13:39.000+0000 |
Description
Encoding authentication credentials creates characters invalid for HTTP headers.
*Test case:*
_index.js_
(function controller(args) {
'use strict';
//Set events
['simplePost', 'basicAuthPost'].forEach(function (proxy) {
$.addListener($[proxy], 'click', prepareRequest);
});
/**
* @method prepareRequest
* @param {object} e Callback event
*/
function prepareRequest(e) {
var withCredentials = true;
if (e.source.id === 'simplePost') {
withCredentials = false;
}
request(withCredentials);
}
/**
* Make a request
* @method request
* @param {boolean} withCredentials Flag for make a auth request or not
*/
function request(withCredentials) {
var client,
config,
url,
data;
data = {
message: 'This is my message'
};
config = {
onload: success,
onerror: error,
timeout: 5000
};
if (withCredentials) {
//Returns HTTP Headers in a success auth
url = 'https://srvasic.upv.es/recursos/error401.asp';
config.withCredentials = true;
//Works
//config.username = 'user';
//config.password = 'p$wd';
//Fails
config.username = 'CR8FB51C9B3C5EDEEB959BCBCF55339FB1';
config.password = '3F853CE4EB1CE3337D51B0CEE707FDCC8E0D';
//Works
//config.username = 'CR8FB51C9B3C5EDE';
//config.password = '3F853CE4EB1CE333';
} elseĀ {
//Echo return
url = 'https://httpbin.org/post';
}
console.log('HTTP CLIENT CONFIG ' + JSON.stringify(config));
client = Ti.Network.createHTTPClient(config);
try {
console.log('URL: ' + url);
client.open('POST', url);
} catch (e) {
console.log('error opening client');
console.log(JSON.stringify(e));
}
try {
client.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
} catch (e) {
console.log('error setting request headers');
console.log(JSON.stringify(e));
}
try {
client.send(data);
} catch (e) {
console.log('error sending data');
console.log(JSON.stringify(e));
}
}
/**
* HttpClient Success Callback
* @method success
* @param {object} e Callback Event
*/
function success(e) {
console.log('Success callback: ' + this.responseText);
}
/**
* HttpClient Error Callback
* @method error
* @param {object} e Callback Event
*/
function error(e) {
console.log('Error callback : ' + e.error);
console.log(this.responseText);
}
$.index.open();
})(arguments[0] || {});
_index.xml_
<Alloy>
<Window class="container" layout="vertical">
<Label id="simplePost">Simple POST</Label>
<Label id="basicAuthPost">Basic Auth POST</Label>
</Window>
</Alloy>
PR: https://github.com/appcelerator/titanium_mobile/pull/9220
[~ybanev] Is their a backport for this ticket?
[~smohammed], sorry for the delay, here is the backport: 6_1_X PR: https://github.com/appcelerator/titanium_mobile/pull/9222
Verified fix in SDK Version 6.2.0.v20170719160617 and SDK Version: 6.1.2.v20170720023139. Test and other information can be found at: Master: https://github.com/appcelerator/titanium_mobile/pull/9220 6_1_X: https://github.com/appcelerator/titanium_mobile/pull/9222