0

Firebase seems to be a moving target, with PHP a stepchild. (google just upgraded stuff in May, too.) I need one simple working example. This is what I have done:

  1. I go to the Firebase website, obtain an apiKey, authDomain and databaseURL. good. I presume none of these are secret because they have to go into various HTML files.

  2. In Auth (left)

    • I add Google as a sign-in provider.

    • I add my OAuth redirect domain to add my site, like mydomain.com.

Now, I want the simplest possible PHP website script that obtains my web visitor's authenticated email address and prints it. Think:

    <?php
        $email = getemail( $apikey, $authDomain, $databaseURL );
        if (empty($email)) die("your user is refuser");
        echo "<html> <body> Your users confirmed email is $email . </body> </html>";
     ?>

(somewhere, in the background, which I hope I won't have to care about (though others may), Google will have to ask my visitor to login first [if not yet] and then for permission to tell my web site the visitor's Google email; if the user refuses or does not have one, my PHP script should get an empty string, otherwise the authenticated email.)

I hope this is easy, but it relies on deep knowledge of the system and this question will, I hope, help not just me. I tried about 20 different tutorials.

/iaw

1 Answer 1

1

I am not sure what you are trying to do. The firebase web sdk is javascript based. You have to sign in to Google on the client side. By the way, you have to use the Firebase provided callback url (from the Firebase Console) as your Google OAuth callback. You can then check currentUser.email for the user's email. You could then send the email to your back end via some xhr request, preferably via https. You could also call getToken on the user and then pass the Firebase id token to your backend and parse that to get all the user info. A php backend library is also in the works.

However, if you only need emails of Google users, perhaps you don't need Firebase and you should just simply use Google sign in SDK.

Sign up to request clarification or add additional context in comments.

1 Comment

checking into the google sign in sdk now. I thought firebase had become its central system here. indeed, all I need is my user's email id (if they permit it).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.