# Handling Facebook / Twitter authentication with PhoneGap

**URL:** <https://forum.ionicframework.com/t/handling-facebook-twitter-authentication-with-phonegap/1228>\
**Category:** ionic-v1\
**Created:** [February 20, 2014, 4:18am UTC](https://forum.ionicframework.com/t/handling-facebook-twitter-authentication-with-phonegap/1228 "2014-02-20T04:18:44Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![neilff](https://avatars.discourse-cdn.com/v4/letter/n/9e8a1a/32.png) [@neilff](https://forum.ionicframework.com/u/neilff)\
**Post date:** [February 20, 2014, 4:18am UTC](https://forum.ionicframework.com/t/handling-facebook-twitter-authentication-with-phonegap/1228/1 "2014-02-20T04:18:44Z")

</div>

What is the best practice when attempting to use facebook or twitter authentication inside a phonegap application?

Traditionally I’ve used Passport.js in my applications and have the user redirected to facebook/twitter login page, and then redirected back to the application, but I’m not sure how to perform this on a mobile application. Or is it the same process? Any help or examples are appreciated.

---

<div class="post-metadata">

**Author:** ![mrameezraja](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mrameezraja/32/12745_2.png) [@mrameezraja](https://forum.ionicframework.com/u/mrameezraja)\
**Post date:** [February 20, 2014, 1:11pm UTC](https://forum.ionicframework.com/t/handling-facebook-twitter-authentication-with-phonegap/1228/2 "2014-02-20T13:11:47Z")

</div>

This can help you:

> **[Wizcorp/phonegap-facebook-plugin](https://github.com/Wizcorp/phonegap-facebook-plugin)**
>
> The official plugin for Facebook in Apache Cordova/PhoneGap - Wizcorp/phonegap-facebook-plugin

---

<div class="post-metadata">

**Author:** ![digitalZ](https://avatars.discourse-cdn.com/v4/letter/d/67e7ee/32.png) [@digitalZ](https://forum.ionicframework.com/u/digitalZ)\
**Post date:** [March 1, 2014, 7:08am UTC](https://forum.ionicframework.com/t/handling-facebook-twitter-authentication-with-phonegap/1228/3 "2014-03-01T07:08:46Z")

</div>

I didn’t sucess with this plugin. Is anyone have a tutorial about it ? It doesn’t work, I’ve tried a lot of various techniques without sucess… I need a login page for my application.

---

<div class="post-metadata">

**Author:** ![gkielwasser](https://avatars.discourse-cdn.com/v4/letter/g/4da419/32.png) [@gkielwasser](https://forum.ionicframework.com/u/gkielwasser)\
**Post date:** [March 1, 2014, 9:20am UTC](https://forum.ionicframework.com/t/handling-facebook-twitter-authentication-with-phonegap/1228/4 "2014-03-01T09:20:29Z")

</div>

I handle authentification with this plugin too. It was a bit tricky to make it work :). I followed the manual Android installation. Moreover I integrate it with Angular.js with [this](https://github.com/Ciul/angular-facebook) module.

---

<div class="post-metadata">

**Author:** ![digitalZ](https://avatars.discourse-cdn.com/v4/letter/d/67e7ee/32.png) [@digitalZ](https://forum.ionicframework.com/u/digitalZ)\
**Post date:** [March 2, 2014, 4:50am UTC](https://forum.ionicframework.com/t/handling-facebook-twitter-authentication-with-phonegap/1228/5 "2014-03-02T04:50:35Z")

</div>

I’ve followed the manual too but I can’t build the app. I got an error:

> $ cordova build  
> Generating config.xml from defaults for platform “android”  
> rm: could not remove directory (code EBUSY): c:\Sites\apps\hello\platforms\andro  
> id\assets\www

> mkdir: path already exists: c:\Sites\apps\hello\platforms\android\assets\www

> Preparing android project  
> Compiling app on platform “android” via command “cmd” /c c:\Sites\apps\hello\pla  
> tforms\android\cordova\build  
> Error: An error occurred while building the android project.Error executing “ant  
> clean -f “c:\Sites\apps\hello\platforms\android\build.xml””:  
> BUILD FAILED  
> c:\Sites\apps\Android\sdk\tools\ant\build.xml:471: The following error occurred  
> while executing this line:  
> C:\Sites\apps\sdk\facebook-android-sdk-3.7\facebook\build.xml:46: sdk.dir is mis  
> sing. Make sure to generate local.properties using ‘android update project’ or t  
> o inject it through an env var

> Total time: 0 seconds

> ```
> at ChildProcess.<anonymous> (c:\Users\Leo\AppData\Roaming\npm\node_modules\cordova\src\compile.js:65:22)
> at ChildProcess.EventEmitter.emit (events.js:98:17)
> at maybeClose (child_process.js:743:16)
> at Process.ChildProcess._handle.onexit (child_process.js:810:5)
> 
> ```

---

<div class="post-metadata">

**Author:** ![digitalZ](https://avatars.discourse-cdn.com/v4/letter/d/67e7ee/32.png) [@digitalZ](https://forum.ionicframework.com/u/digitalZ)\
**Post date:** [March 2, 2014, 5:17am UTC](https://forum.ionicframework.com/t/handling-facebook-twitter-authentication-with-phonegap/1228/6 "2014-03-02T05:17:15Z")

</div>

I’ve resolved this error running `android update lib-project -p .` in the folder facebook/ do sdk.

---

<div class="post-metadata">

**Author:** ![mlundela](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@mlundela](https://forum.ionicframework.com/u/mlundela)\
**Post date:** [March 20, 2014, 1:24pm UTC](https://forum.ionicframework.com/t/handling-facebook-twitter-authentication-with-phonegap/1228/7 "2014-03-20T13:24:42Z")

</div>

Would you mind provide the setup for this [module](https://github.com/Ciul/angular-facebook) to work in a native environment? My angular controller is set up as described in the [README](https://github.com/Ciul/angular-facebook), and I have included files from the facebook sdk and the module in my index.html. I works in the browser if I substitute facebook-js-sdk.js for [http://connect.facebook.net/en\_US/all.js](http://connect.facebook.net/en_US/all.js)

```
<script src="lib/js/cdv-plugin-fb-connect.js"></script>

<!-- For native -->
<script src="lib/js/facebook-js-sdk.js"></script>
<!-- For webapp -->
<!--<script src="http://connect.facebook.net/en_US/all.js"></script>-->

<script src="lib/js/angular-facebook.js"></script>
<script src="lib/js/angular-facebook-phonegap.js"></script>

```

Edit: I just posted this question on [stackoverflow](https://stackoverflow.com/questions/22536370/facebook-authentication-in-cordova-angularjs-app)

---

<div class="post-metadata">

**Author:** ![gkielwasser](https://avatars.discourse-cdn.com/v4/letter/g/4da419/32.png) [@gkielwasser](https://forum.ionicframework.com/u/gkielwasser)\
**Post date:** [March 20, 2014, 7:59pm UTC](https://forum.ionicframework.com/t/handling-facebook-twitter-authentication-with-phonegap/1228/8 "2014-03-20T19:59:42Z")

</div>

Hi,

I tried to give you the most usefull steps in your [question](https://stackoverflow.com/questions/22536370/facebook-authentication-in-cordova-angularjs-app/22543795#22543795) on stackoverflow. I hope it will help you!

---

<div class="post-metadata">

**Author:** ![breno](https://avatars.discourse-cdn.com/v4/letter/b/c68b51/32.png) [@breno](https://forum.ionicframework.com/u/breno)\
**Post date:** [March 22, 2014, 6:44pm UTC](https://forum.ionicframework.com/t/handling-facebook-twitter-authentication-with-phonegap/1228/9 "2014-03-22T18:44:41Z")

</div>

I’m also trying to do a Facebook login with an Ionic starter template app but I’m getting this error when I try to build the app:

`#import "FacebookSDK.h" !'FacebookSDK.h' file not found`

I have the FacebookSKD.Framework in the Framerwork folder in my project, following the steps on [phonegap-facebook plugin](https://github.com/phonegap/phonegap-facebook-plugin). any thoughts?

---

<div class="post-metadata">

**Author:** ![mlundela](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@mlundela](https://forum.ionicframework.com/u/mlundela)\
**Post date:** [April 11, 2014, 12:08pm UTC](https://forum.ionicframework.com/t/handling-facebook-twitter-authentication-with-phonegap/1228/10 "2014-04-11T12:08:56Z")

</div>

Try changing the path to

```
#import "FacebookSDK/FacebookSDK.h"
```

---

<div class="post-metadata">

**Author:** ![vmaliko](https://avatars.discourse-cdn.com/v4/letter/v/fbc32d/32.png) [@vmaliko](https://forum.ionicframework.com/u/vmaliko)\
**Post date:** [September 15, 2014, 10:03pm UTC](https://forum.ionicframework.com/t/handling-facebook-twitter-authentication-with-phonegap/1228/11 "2014-09-15T22:03:18Z")

</div>

I actually needed something like that for a few apps I’m working on. I spent quite some time investigating this and was able to achieve something I was happy with, just thought I’d share some of the stuff I’ve done.

In addition to email/password authentication I’ve added some social authentication which kind of works in the same way.

You can download the [apk](https://drive.google.com/file/d/0B9GTa-_sqdVJNnZwbzl1TGQxZFE/edit?usp=sharing) and test it.

If this is what you’re looking for you can checkout both the client side code at : [https://github.com/malikov/Authenticate.me-client-cordova-ionic](https://github.com/malikov/Authenticate.me-client-cordova-ionic)

And the server side code at : [https://github.com/malikov/Authenticate.me-Node-Server](https://github.com/malikov/Authenticate.me-Node-Server)

Best of luck

---

<div class="post-metadata">

**Author:** ![grege](https://avatars.discourse-cdn.com/v4/letter/g/ccd318/32.png) [@grege](https://forum.ionicframework.com/u/grege)\
**Post date:** [September 22, 2014, 2:11am UTC](https://forum.ionicframework.com/t/handling-facebook-twitter-authentication-with-phonegap/1228/12 "2014-09-22T02:11:57Z")

</div>

Nice stuff @vmaliko. I’ve been working with Satellizer for web clients and was about to try implement with Ionic, but I plan to give this a go.

---

<div class="post-metadata">

**Author:** ![vmaliko](https://avatars.discourse-cdn.com/v4/letter/v/fbc32d/32.png) [@vmaliko](https://forum.ionicframework.com/u/vmaliko)\
**Post date:** [September 26, 2014, 5:23am UTC](https://forum.ionicframework.com/t/handling-facebook-twitter-authentication-with-phonegap/1228/14 "2014-09-26T05:23:39Z")

</div>

@grege thanks let me know if you have any questions or issues.

---

<div class="post-metadata">

**Author:** ![s\_hallak](https://avatars.discourse-cdn.com/v4/letter/s/8797f3/32.png) [@s\_hallak](https://forum.ionicframework.com/u/s_hallak)\
**Post date:** [December 7, 2014, 10:18pm UTC](https://forum.ionicframework.com/t/handling-facebook-twitter-authentication-with-phonegap/1228/15 "2014-12-07T22:18:45Z")

</div>

any update , on using satellizer with ionic

---

<div class="post-metadata">

**Author:** ![pcbulai](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/pcbulai/32/75140_2.png) [@pcbulai](https://forum.ionicframework.com/u/pcbulai)\
**Post date:** [January 12, 2015, 10:26am UTC](https://forum.ionicframework.com/t/handling-facebook-twitter-authentication-with-phonegap/1228/16 "2015-01-12T10:26:20Z")

</div>

I want to give the users the ability to login with Facebook and Twitter but not by opening a link with inAppBrowser plugin. I’d like to be able to access the Facebook/Twitter apps already installed on the mobile devices(or the accounts from Settings -\> Twitter/Facebook on iOS), where the user grants access, and then gets back to my app logged in. Any ideas?

It seems there’s a way to do this with the Facebook plugin previously mentioned. But what about Twitter?

I found a couple similar questions on stackoverflow but they had no answers.

---

<div class="post-metadata">

**Author:** ![brent](https://avatars.discourse-cdn.com/v4/letter/b/ec9cab/32.png) [@brent](https://forum.ionicframework.com/u/brent)\
**Post date:** [January 12, 2015, 5:09pm UTC](https://forum.ionicframework.com/t/handling-facebook-twitter-authentication-with-phonegap/1228/17 "2015-01-12T17:09:10Z")

</div>

@pcbulai - not the easiest of approaches, but you could do something like this: [Native authentication leading to a crosswalk webview](http://forum.ionicframework.com/t/native-authentication-leading-to-a-crosswalk-webview/15510) - put the login screen as an activity inside of Android Studio (or XCode in the case of iOS) and have it just send you to a webview when you’re authenticated.

---

<div class="post-metadata">

**Author:** ![pcbulai](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/pcbulai/32/75140_2.png) [@pcbulai](https://forum.ionicframework.com/u/pcbulai)\
**Post date:** [January 13, 2015, 8:17pm UTC](https://forum.ionicframework.com/t/handling-facebook-twitter-authentication-with-phonegap/1228/18 "2015-01-13T20:17:27Z")

</div>

Thanks for the tip. I’ll take it for a spin and hopefully it’ll solve my problem.

---

<div class="post-metadata">

**Author:** ![ScottN](https://avatars.discourse-cdn.com/v4/letter/s/eb8c5e/32.png) [@ScottN](https://forum.ionicframework.com/u/ScottN)\
**Post date:** [January 13, 2015, 8:29pm UTC](https://forum.ionicframework.com/t/handling-facebook-twitter-authentication-with-phonegap/1228/19 "2015-01-13T20:29:58Z")

</div>

@pcbulai if you get anywhere with this, please update this thread, I’ve found way too many abandoned threads on this topic on the web, we all need a solid solution available for Android and iOS. I’ve been looking for a native app solution for Facebook login + Phonegap + AngularJS for a while. I’ve been using the InAppBrowser for a while and whenever I’m present when someone uses my app and they see that it doesn’t use native, they get confused or worse yet “I can’t remember my Facebook password”… which is really their problem, but the user flow is interrupted with InAppBrowser.

---

<div class="post-metadata">

**Author:** ![pcbulai](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/pcbulai/32/75140_2.png) [@pcbulai](https://forum.ionicframework.com/u/pcbulai)\
**Post date:** [January 14, 2015, 8:39am UTC](https://forum.ionicframework.com/t/handling-facebook-twitter-authentication-with-phonegap/1228/20 "2015-01-14T08:39:56Z")

</div>

@ScottN I agree the social login is a big problem. I’m fairly new to mobile development and when I saw that I can do the social login I was really happy. But that lasted about 5 minutes, until I realised that you’re not supposed to login with facebook/twitter in an app by entering your social networks credentials but by using the native apps. So yeah, I’m kinda stuck in solving this right now.

Of course I will update the topic, regardless of what the end result will be. Stay put!

---

<div class="post-metadata">

**Author:** ![nicraboy](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/nicraboy/32/6917_2.png) [@nicraboy](https://forum.ionicframework.com/u/nicraboy)\
**Post date:** [January 14, 2015, 3:41pm UTC](https://forum.ionicframework.com/t/handling-facebook-twitter-authentication-with-phonegap/1228/21 "2015-01-14T15:41:13Z")

</div>

Hi @neilff,

You might take a look at the ngCordova module I made for Oauth. I wrote about it here:

[http://ionicframework.com/blog/oauth-ionic-ngcordova/](http://ionicframework.com/blog/oauth-ionic-ngcordova/)

It will open a browser pointed at the official provider endpoints so when you enter your credentials, you’ll be entering them directly on the providers website. The logic in the module will determine what to do after.

Regards,

[Next page](https://forum.ionicframework.com/t/handling-facebook-twitter-authentication-with-phonegap/1228.md?page=2)
