Error using FirebaseUI Facebook Auth in Cordova app - angularjs

I am trying to set up Facebook and Google authentication through FirebaseUI in my Cordova/PhoneGap app, and I am receiving an error when the "Sign in with X" buttons are clicked. The error states the following:
Refused to display 'https://www.facebook.com/login.php?skip_api_login=1&api_key=643683385780436…_&display=page&locale=en_US&logger_id=05e536a7-cf68-44a3-825b-63dd3edd5b0a' in a >frame because it set 'X-Frame-Options' to 'DENY'.
After a little research I've learned that the X-Frame option is set by the provider, and I cannot change it. I've looked through threads about how to work around this, but the answers either don't solve the problem or go over my head. Any explanation would be much appreciated.
My code is as follows:
login controller:
app.controller("loginCtrl", function ($scope, $state, $rootScope, $firebaseAuth, $location) {
// Firebase config.
var config = {
apiKey: "",
authDomain: "",
};
// FirebaseUI config.
var uiConfig = {
'queryParameterForWidgetMode': 'mode',
'signInSuccessUrl': '/home',
'signInOptions': [
firebase.auth.FacebookAuthProvider.PROVIDER_ID,
firebase.auth.GoogleAuthProvider.PROVIDER_ID
],
// Terms of service url.
//'tosUrl': '<your-tos-url>',
'callbacks': {
'signInSuccess': function (currentUser, credential, redirectUrl) {
// Do something.
// Return type determines whether we continue the redirect automatically
// or whether we leave that to developer to handle.
console.log('success');
return true;
}
}
};
// Initialize the FirebaseUI Widget using Firebase.
var app = firebase.initializeApp(config);
var auth = app.auth();
var ui = new firebaseui.auth.AuthUI(auth);
// The start method will wait until the DOM is loaded.
ui.start('#firebaseui-auth-container', uiConfig);
});
login.html
<ion-view title="Sign In">
<ion-content>
<div>
<center>
<br />
<h1>Sign In</h1>
</center>
<div id="firebaseui-auth-container"></div>
</div>
</ion-content>
relevant index.html
<!-- FirebaseUI for Facebook Auth -->
<script src="https://www.gstatic.com/firebasejs/live/3.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/live/3.0/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/ui/0.4.0/firebase-ui-auth.js"></script>
<link type="text/css" rel="stylesheet" href="https://www.gstatic.com/firebasejs/ui/0.4.0/firebase-ui-auth.css" />
Thanks!
Sam

I am also trying to set up Facebook and Google authentication through FirebaseUI in my Cordova/PhoneGap app. However, while reading the FirebaseUI for Web — Auth docs I found the following:
FirebaseUI fully supports all recent browsers. Signing in with
federated providers (Google, Facebook, Twitter, Github) is not yet
supported in non-browser environments (Cordova, React Native,
Ionic...) nor Chrome extensions.
So, unfortunately it seems that using FirebaseUI with a Cordova app is not supported yet.

Related

Migrating Firebase 2.x to 3.4.1 AngularJS For Google OAuth

I am new to Angular & Firebase. I am currently developing an Ionic app. Somehow I came to know that, to use Firebase, I need to set up authentication system (I prefer Google).
It was not easy to integrate the code into AngularJS which were mentioned in official Firebase website. So I just picked up someone's working code and replaced his Firebase database URL to mine, I could get it done. But it was a mistake.
This is the unchanged code and his output (which is working as expected).
index.html
<script src="lib/angularfire/dist/angularfire.min.js"></script>
<script src="lib/firebase/firebase.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script src="js/services.js"></script>
app.js
angular.module('starter', ['ionic', 'starter.controllers', 'starter.services', 'firebase'])
.constant('FirebaseUrl', 'https://ionicle.firebaseio.com/')
.service('rootRef', ['FirebaseUrl', Firebase])
So first, I removed his Firebase URL to add mine and got this error:
We have detected that you are using the v2.x or lower authentication SDKs with a project that was created at console.firebase.google.com. You must use the 3.0.0 or greater authentication SDKs with projects that have been created in the new console.
Then I updated firebase.js file to 3.4.1 version. Then I got a Reference error in browser's Dev console: ReferenceError: Firebase is not defined
.service('rootRef', ['FirebaseUrl', Firebase])
So what I finally need is a working Google OAuth with Firebase 3.x and AngularJS.
Although you didn't provide enough examples of your code (dependency injection is not enough), I think that the main problem you are having is that you are using old examples of the code with the new Firebase version.
Things like this:
var app = angular.module('app', ['firebase']);
app.controller('Ctrl', function($scope, $firebaseAuth) {
var ref = new Firebase('https://...');
$scope.authObj = $firebaseAuth(ref);
...
});
are changed into this:
var app = angular.module('app', ['firebase']);
app.controller('Ctrl', function($scope, $firebaseAuth) {
var config = {
apiKey: "***",
authDomain: "***.firebaseapp.com",
databaseURL: "https://***.firebaseio.com",
storageBucket: "***.appspot.com",
messagingSenderId: "***"
};
firebase.initializeApp(config);
$scope.authObj = $firebaseAuth(firebase.auth());
...
});
Then on that authObj you can add a provider for the client you want to use to authenticate (Google/GitHub/Facebook...):
var provider = new firebase.auth.GoogleAuthProvider();
$scope.authObj.$signInWithPopup(provider).then(function(result) {
console.log(result);
});
Keep in mind that you must enable Authentication with Google (or any other provider) in your Firebase console. For detailed instructions please check this link.

No Permission error using Firebase

I am trying to add Firebase for the first time to an ionic application. I have set up my project and referenced the javascript files however when I run the application I see the error 'Error: Permission Denied'
I have not yet set up authentication in my app but, if I am understanding things properly I shouldn't need to do this while I am just testing.
My index.html contains the following:
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- Firebase -->
<script src="https://cdn.firebase.com/js/client/2.2.4/firebase.js"></script>
<!-- AngularFire -->
<script src="https://cdn.firebase.com/libs/angularfire/1.2.0/angularfire.min.js"></script>
While the app.js has the following lines:
angular.module('starter', ['ionic', 'firebase'])
.factory("Items", function($firebaseArray) {
var itemsRef = new Firebase("https://todo-83e58.firebaseio.com/items");
return $firebaseArray(itemsRef);
})
.controller('ListCtrl', function($scope, $ionicListDelegate, Items) {
$scope.items = Items;
$scope.addItem = function () {
var name = prompt("what do you need to buy?");
if (name) {
$scope.items.$add({"name": name});
}
};
I would be grateful for any pointers on how to get the basics right as I have tried following the information on the Firebase site and I seem to have it all set up correctly. Am I misunderstanding the authentication or shouldI be able to write to the database without setting this up first ?
It sounds that your Security & Rules isn't giving you access to items. Please make sure to spend some time reading the S&R documentation.
If you are only testing the application and don't want to care about it now just set it to full read and write.
On the new console go to Database > Rules.
{
"rules": {
".read": true,
".write": true
}
}

Using Adal JS in an Angular JS App for Office 365

I am creating a basic html site that is using Angular JS and Adal Js to connect to Office 365. Below are the issues faced -
The page is not redirecting for login purpose.
Getting "unexpected token" and "[$injector:modulerr]" error in the
browser console.
I have configured application in Azure AD with following details -
SIGN-ON URL : http://localhost: port number/
APP ID URI : https:// tenant name/ThomasO365
REPLY URL : http://localhost: port number/
Exchange and SharePoint permission has been provided to the application.
Application Code
var o365CorsApp = angular.module("o365CorsApp", ['ngRoute', 'AdalAngular']) // loading the ADAL JS Angular module
o365CorsApp.config(['$routeProvider', '$httpProvider', 'adalAuthenticationServiceProvider',
function($routeProvider, $httpProvider, adalProvider) {
$routeProvider
.when('/', {
controller: 'HomeController',
templateUrl: 'index.html',
requireADLogin: true
})
.otherwise({
redirectTo: '/'
});
var adalConfig = {
tenant: '<tentant name>',
clientId: '<client id>',
extraQueryParameter: 'nux=1',
endpoints: {
"https://outlook.office365.com/api/v1.0": "https://outlook.office365.com/"
}
};
adalProvider.init(adalConfig, $httpProvider);
}
]);
o365CorsApp.factory('o365CorsFactory', ['$http',
function($http) {
var factory = {};
factory.getContacts = function() {
return $http.get('https://outlook.office365.com/api/v1.0/me/contacts')
}
return factory;
}
]);
o365CorsApp.controller("HomeController", function($scope, $q, o365CorsFactory) {
o365CorsFactory.getContacts().then(function(response) {
$scope.contacts = response.data.value;
});
});
<html ng-app="o365CorsApp">
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-route.min.js"></script>
<script type="text/javascript" src="adal-angular.js"></script>
<script type="text/javascript" src="adal.js"></script>
<script type="text/javascript" src="app.js"></script>
</head>
<body ng-controller="HomeController">{{contacts.Email}}
<br/>
<p></p>
</body>
</html>
I am referencing this article. I am using Brackets instead of Visual Studio.
Note-
Tenant and Client ID are correct.
Oauth2AllowImplicitFlow is set to true in manifest file.
I'm going through that article and finding some omissions. Here's some issues I found (don't know if they're causing your error though):
Cut and paste of the code introduces extra spaces in the URL's in app.js. Make sure there are no trailing spaces or spaces between the ? and the rest of the URLs.
The code in app.js has values for tenant and clientId that are obviously for the author, and they never tell you how to replace those with valid values for your app. You can get the correct clientId from the Azure Management Portal. tenant is a bit trickier to get the GUID, but luckily you can just put your domain name there (like contoso.onmicrosoft.com).
Other things to check:
Make sure that you enabled the implicit OAuth2 flow by downloading the manifest, setting oauth2AllowImplicitFlow to true, and reuploading (per the article).
Make sure you are signing into the app using an account that is in the same domain as the one you specify in the tenant property.
Try changing your reply URL to remove index.html. That may be messing with the ADAL libraries token parser.

Firebase Simple Login with twitter OAuth

I'm trying to implement twitter login in my angularfire application, and can't seem to figure it out. I've set my callback URL to https://auth.firebase.com/v2/MyFIREBASE/auth/twitter/callback, and the app does display a popup that hangs for about 3 seconds. The URL on the popup is https://auth.firebase.com/v2/MyFIREBASE/auth/twitter/callback.
In my code, I have copy and pasted directly from the angularfire auth section.
HTML:
<div ng-controller="SampleCtrl">
<div ng-show="auth.user">
<p>Hello, {{auth.user.displayName}}</p>
<button ng-click="auth.$logout()">Logout</button>
</div>
<div ng-hide="auth.user">
<p>Welcome, please log in.</p>
<button ng-click="auth.$login('twitter')">Login</button>
</div>
</div>
JavaScript:
app.factory("simpleLogin",
["$firebaseSimpleLogin", function($firebaseSimpleLogin) {
var ref = new Firebase("https://MyFIREBASE.firebaseio.com/");
return $firebaseSimpleLogin(ref);
}]
);
app.controller("SampleCtrl",
["$scope", "simpleLogin", function($scope, simpleLogin) {
$scope.auth = simpleLogin;
}]
);
It looks like there's a version mismatch at play here - the callback URL you're using is for a more recent version of the Firebase web client (>= v1.1.0) than is currently bundled with AngularFire (which uses the older, deprecated Firebase Simple Login client). A new version of AngularFire will be released soon which supports the newer API.
In the meantime, you can either skip the AngularFire factory methods and call into the Firebase client directly (i.e. ref.authWithOAuthPopup('twitter', ...)) with the Firebase web client >= v1.1.0 or use the older version with Firebase Simple Login, and an old-format callback URL, documented at https://github.com/firebase/firebase-simple-login/tree/master/docs/v1.

How to use API KEY with YouTube in angularjs and list videos in a playlist?

I want to list a bunch of videos from YouTube in my mobile app using angularjs.
Preferrably I'd like to list all videos of a user/channels specific playlist.
I've gotten the API KEY from Google Developer Console but I don't understand how and where to use it. In this documentation they only go over the oauth method. https://developers.google.com/youtube/v3/code_samples/javascript#authorizing_requests
I tried using the example code straight up from that documentation only to get a message saying I have to authenticate first.
I'd really appreciate some help into this.
How do authenticate using the api key and secondly how to make the request to get the videos in a playlist.
ps. I'm a newbie developer and I'm using angularjs and ionic framework for my first learning project. I'm fresh out of Codeschool's courses in css, jquery, javascript, backbone and angular. ds.
Thanks!
1. How to use the API
If you want videos of a channel you need to use the YouTube API V3. Use youtube.search.list
with the parameters :
part=id, snippet
channelId=ID OF THE CHANNEL
order=date
type=video
How to find ID of a YouTube Channel ?
You can find the id of a channel with his channel name with http://mpgn.github.io/YTC-ID/
More information of youtube.search.list right here.
This is a live demo.
2. With Javascript ?
First, you need to creat a project in console.google.developers.
Enable the API YouTube API V3 (set to on).
In credential part, creat a public access key.
Also if it's a public app, you may interest by : How to protect my public API key ?
This is the basic code to get the videos of a channel :
<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-2.1.1.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script>
function googleApiClientReady() {
var apiKey = 'your api key';
gapi.client.setApiKey(apiKey);
gapi.client.load('youtube', 'v3', function() {
request = gapi.client.youtube.search.list({
part: 'snippet',
channelId: 'UCqhNRDQE_fqBDBwsvmT8cTg',
order: 'date',
type: 'video'
});
request.execute(function(response) {
console.log(response);
});
});
}
</script>
<script src="https://apis.google.com/js/client.js?onload=googleApiClientReady"></script>
</body>
</html>
3. With AngularJS ?
With AngularJS you need to creat a service 'google' for example, and you can use the service in your controllers.
An sample example : https://gist.github.com/jakemmarsh/5809963
You don't need the part with authentification.
Using deferred is important in this case.
Example in the controller
'use strict';
function init() {
window.initGapi(); // Calls the init function defined on the window
}
angular.module('team')
.controller('VideosCtrl', function ($scope, $window, $sce, googleService) {
$window.initGapi = function() {
$scope.$apply($scope.getChannel);
};
$scope.getChannel = function () {
googleService.googleApiClientReady().then(function (data) {
$scope.channel = data;
}, function (error) {
console.log('Failed: ' + error)
});
};
});
Example in the service googleService
.service('googleService', ['$http', '$q', function ($http, $q) {
var deferred = $q.defer();
this.googleApiClientReady = function () {
gapi.client.setApiKey('YOU API KEY');
gapi.client.load('youtube', 'v3', function() {
var request = gapi.client.youtube.playlistItems.list({
part: 'snippet',
playlistId: 'PLila01eYiSBjOtR8oqXkY0i5c1QS6k2Mu',
maxResults: 8
});
request.execute(function(response) {
deferred.resolve(response.result);
});
});
return deferred.promise;
};
}])
You need to add this line to your index.html
<script src="https://apis.google.com/js/client.js?onload=init"></script>
Hope it's help you !
You have to use Google APIs Client Library so that gapi object will be defined and examples from google will work.
Include this in the bottom of the page:
<script src="https://apis.google.com/js/client.js?onload=googleApiClientReady"></script>
And than define callback which will proceed with authorization and your logic:
googleApiClientReady = function() {
gapi.auth.init(function() {
// Other code following the example
});
}
In general as per Google documentation there are
The application loads the JavaScript client library.
The application references its API key, which authenticates the application with Google services.
If the application needs access to the user's personal information, it opens a session with a Google auth server. The auth server opens a dialog box which prompts the user to authorize the use of personal information.
The application loads the API for the Google service.
The application initializes a request object (also called a service object) that specifies the data to be returned by the API.
The application executes the request and processes the data returned by the API.
Here is a working example of basic google API authorization process

Resources