Auth.gettoken and Angular Ionic

Hi, i've been struggling with the basic attempt to log into elgg from my iOS app.. i'm using ionic and angular.

what on earth am i doing wrong? running elgg 2.3.5

I see two calls going out, the first returns:

{"status":-1,"message":"auth.gettoken must be called using 'POST'"}

the second response i get is:

"Response {_body: "{"status":-1,"message":"Missing parameter username in method auth.gettoken"}", status: 200, ok: true, statusText: "OK", headers: Headers, …}"

login(credentials) {
return new Promise((resolvereject=> {
let headers = new Headers();
headers.append('Authorization','Bearer ');
let options = new RequestOptions({headers: headers});


var jsonMSG = '';
for (var prop in credentials) {
jsonMSG += encodeURIComponent(prop) + '=' +
encodeURIComponent(credentials[prop]) + '&';


//'auth.gettoken', JSON.stringify(credentials), {headers: headers})'auth.gettoken'jsonMSG.substring(0jsonMSG.length - 1), options)
.subscribe(res => {
}, (err=> {
  • I am not exactly sure how ionic prepares the request, but a) you have a typo in your Content Type header, b) it seems you are sending a url encoded string in POST body. Elgg is not able to access your variables.

    1) Either send a POST request with multiplart/form-data content type and put your variables into the form data boundaries,

    or 2) Send a POST request, but put your varialbles into the URL's query string, as if you were sending a GET request

    Elgg uses Symfony's HTTP foundation, so you may find some more info their docs on how to build a proper HTTP request that is understood by Elgg.

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking