How to use Dreamfactory OAuth in Ionic apps

I am trying to implement Dreamfactory OAuth in Ionic app.
I am following this resource for implementation:
https://wiki.dreamfactory.com/DreamFactory/Tutorials/Using_OAuth

This is the call I am making:

$http.post(‘/api/v2/user/session?service=facebook’).then(function (result) {
console.log("result: "+ JSON.stringify(result));
});

The log above shows me json data as it itself redirects to the facebook url returned by the call and it just returns HTML for that facebook page.

Is there a different approach I should be using in hybrid/Ionic apps for DF OAuth login?

1 Like

I think that you need to follow a similar procedure to what the ng-cordova-oauth plugin does.

That is, open a new window ($window.open("your_server_url/?service=facebook", "_blank", "location=no,clearsessioncache=no,clearcache=no") using InAppBrowser), and listen for the child window’s loadstart / loadstop events (only works when running the app on a phone with the InAppBrowser plugin installed) to intercept the authentication code.

Then you need to POST that auth code to /user/session?service... to actually log in Dreamfactory.

1 Like

This is what solved it for me:
Simply set request header as:

$httpProvider.defaults.headers.common[‘X-Requested-With’] = ‘XMLHttpRequest’;

Someone else answered this for me so here is the link to question on stackoveflow:

1 Like