# How to use Dreamfactory OAuth in Ionic apps

**URL:** <https://community.dreamfactory.com/t/how-to-use-dreamfactory-oauth-in-ionic-apps/2896>\
**Category:** REST API\
**Created:** [June 28, 2016, 9:57am UTC](https://community.dreamfactory.com/t/how-to-use-dreamfactory-oauth-in-ionic-apps/2896 "2016-06-28T09:57:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrvipinkashyap](https://avatars.discourse-cdn.com/v4/letter/m/977dab/32.png) [@mrvipinkashyap](https://community.dreamfactory.com/u/mrvipinkashyap)\
**Post date:** [June 28, 2016, 9:57am UTC](https://community.dreamfactory.com/t/how-to-use-dreamfactory-oauth-in-ionic-apps/2896/1 "2016-06-28T09:57:26Z")

</div>

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](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?

---

<div class="post-metadata">

**Author:** ![rbarriuso](https://avatars.discourse-cdn.com/v4/letter/r/e99b99/32.png) [@rbarriuso](https://community.dreamfactory.com/u/rbarriuso)\
**Post date:** [July 28, 2016, 1:41pm UTC](https://community.dreamfactory.com/t/how-to-use-dreamfactory-oauth-in-ionic-apps/2896/3 "2016-07-28T13:41:44Z")

</div>

I think that you need to follow a similar procedure to what the [ng-cordova-oauth plugin](https://github.com/nraboy/ng-cordova-oauth) does.

That is, open a new window (`$window.open("your_server_url/?service=facebook", "_blank", "location=no,clearsessioncache=no,clearcache=no")` using [InAppBrowser](https://github.com/apache/cordova-plugin-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.

---

<div class="post-metadata">

**Author:** ![mrvipinkashyap](https://avatars.discourse-cdn.com/v4/letter/m/977dab/32.png) [@mrvipinkashyap](https://community.dreamfactory.com/u/mrvipinkashyap)\
**Post date:** [October 14, 2016, 1:09pm UTC](https://community.dreamfactory.com/t/how-to-use-dreamfactory-oauth-in-ionic-apps/2896/4 "2016-10-14T13:09:11Z")

</div>

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:

> <https://stackoverflow.com/questions/38073440/how-to-add-dreamfactory-oauth-facebook-login-in-ionic>
