Hi Tobias,
It's easy to use basic autentification with appery.io
In accordance to RFC http://tools.ietf.org/html/rfc2617 when basic auth need request should have "Authorization" header.
So there is no "login" request. You can accept to any web page/resource with basic auth.
Please follow these steps to implement basic autentification to your web resource:
1 Open "App settings". Navigate to "External resources" and add following url: http://prntscr.com/3lodbi/direct
pre
http://crypto-js.googlecode.com/files/2.5.3-crypto-min.js
/pre
2 Create new JS asset. And fill it with following JS. http://prntscr.com/3loeg6/direct
pre
function getAuth() {
//You should replace "user:password" string with your values.
var bytes = Crypto.charenc.Binary.stringToBytes("user:password");
var base64 = Crypto.util.bytesToBase64(bytes);
return "Basic " + base64;
}
/pre
3 Create REST service. And call it "getInfoWithBasic".
4 Set "getInfoWithBasic" with following settings(see screen shot):
http://prntscr.com/3lofgx/direct
5 Navigate to "Request" tab and add "Authorization" parameter. Check "Header" option: http://prntscr.com/3log6e/direct
6 Add datasoruce with service "getInfoWithBasic" on the "data" tab of the page and call it "getInforWithBasicDataSource". http://prntscr.com/3lohdb/direct
7 Click "Edit Mapping". Open "Request tab" and click "Add JS" on "Authorization" field. http://prntscr.com/3lohqp/direct
8 JS Editor will appear. Populate it with following code: http://prntscr.com/3loi5k/direct
pre
return getAuth();
/pre
9 Open "EVENTS" bottom panel. And add "Complete" event handler to your datasource. And populate it with following code: http://prntscr.com/3lok18/direct
pre
//This is just a test code that's show you response from the server.
console.log("Response from server with basic auth = " + jqXHR.responseText);
alert("Response from server with basic auth = " + jqXHR.responseText);
/pre
10 Add button to the page. And set "Click" event handler with action - invoke service "getInforWithBasicDataSource". http://prntscr.com/3lokr4/direct
11 Run your app on this page in chrome browser. And open "net" tab of browser debuger.
12 Click on Button. And you will get the alert with server response. http://prntscr.com/3loljj/direct
13 Close alert and open request in "Net" tab of the debugger. http://prntscr.com/3lomhv/direct
That's all.
Regards.