Web Google authentication with firebase
Asked Answered
B

3

12

uncaught exception: Error: This operation is not supported in the environment this application is running on. "location.protocol" must be http, https or chrome-extension and web storage must be enabled.

var config = {
apiKey: "*****",
authDomain: "******",
};
firebase.initializeApp(config);
var provider = new firebase.auth.GoogleAuthProvider();
provider.addScope('profile');
provider.addScope('https://www.googleapis.com/auth/drive');
firebase.auth().signInWithRedirect(provider);
alert(1);
}
Bitolj answered 21/6, 2017 at 16:16 Comment(4)
looks like a problem with http and drive sdk requires your authdomain to be https://Advice
What’s your actual question here?Opacity
that code run only on localhost. is it possible to run that code without any web browserBitolj
Other docs suggest running firebase serve --but I'm unsure what is the default port.Turbot
C
8

uncaught exception: Error: This operation is not supported in the environment this application is running on. "location.protocol" must be HTTP, HTTPS or chrome-extension and web storage must be enabled.

Recently even i faced the same error.

You are opening this file directly in the browser without any web server. Firebase authentication won't work if you open the file directly. Try to load your HTML through web server it should solve your issue. The reason behind this bug is when you use authentication services they will use web storage. web storage does not work when you open an HTML file directly without any web browser

For example, use apache and open through apache like http://localhost/filename.html in the browser

Coney answered 21/6, 2017 at 16:30 Comment(11)
thanks for ur reply. yeah that is true.i use that code in adobe cep extension it does not have any web browser. so is it possible to run that code without web server or web browserBitolj
sorry no idea.@BitoljConey
is it possible with nodejsBitolj
yes its possible. just create expressjs server and add your file thereConey
I am new in node. can you pls give any example with express js.Bitolj
follow this tutorial mfranc.com/node-js/node-js-simple-web-server-with-expressConey
sorry i can't understand that. that code includes port so app.listen(port) also worked in localhost!Bitolj
did you create server with port. if so open it using localhost:portConey
is it possible to create server without port. my project must run without localhostBitolj
without port we cant create ant server. by default http runs on port 80. if you want to run without port means run nodejs on port 80 with root permissionConey
@Dineshundefined i have used it with the nodejs server and call route by browser and bu another server (angular) and always got this error !!Aviv
B
-1

Try this code. It should work.

    var config = {
    apiKey: "*****",
    authDomain: "******",
    };
    firebase.initializeApp(config);
    var provider = new firebase.auth.GoogleAuthProvider();
    provider.addScope('profile');
    provider.addScope('https://www.googleapis.com/auth/drive');
    firebase.auth().signInWithRedirect(provider);
    //add the code below to your previous lines
    firebase.auth().getRedirectResult().then(function(authData) {
        console.log(authData);
    }).catch(function(error) {
        console.log(error);
    });
Bazemore answered 21/6, 2017 at 16:28 Comment(2)
thank for ur reply. sorry that code not solved my problemBitolj
This is not a solution. The problem still persists in iOS for Firebase auth by GooglePneumato
N
-3

Most simple way.... just upload your files on github and run with github page(i.e. https://ur name.github.io/yr dir/yr html file.

Naevus answered 26/3, 2019 at 13:32 Comment(1)
This would rely on adding Github as an authorised domain for accessing your Firebase project. In turn, this would allow any Github-hosted page access to your project.Osprey

© 2022 - 2024 — McMap. All rights reserved.