Giter Site home page Giter Site logo

firebaseauth-example's Introduction

Install

Symfony

composer install
cp .env .env.local

Google Auth

Recommended way

  • Create a new Firebase project on the Firebase console
  • In the Authentication menu, choose the Sign-in method tab and enable the Google provider.
  • You will see the associated Web client id (GOOGLE_CLIENT_ID) and Web client secret (GOOGLE_CLIENT_SECRET), which you need to put into your .env.local file to the corresponding variables.
  • After this when you try to sign in with google, an error will arise about the redirect url. Follow the link to the Google cloud console and add the redirect to the Authorized redirect URIs list for your web client API key. The correct redirect url is in the error message too (http://yoururl/login-check)
  • On this admin (Google Cloud Console), you will have to create a Service account key for Firebase. In the Credentials menu, press the Create credentials dropdown button and choose Service account key. Choose a service account (if you created the project from firebase, then you will already have one) and create a JSON key. Put the json into the local var folder and name it exactly firebase-service-account.json. Or if you use Google App Engine, you can use the autodiscovery feature.

Separate Firebase and Google projects (advanced)

If you create a separate Firebase and separate Google Cloud project, then you will have to add your Google project's client ID to the Firebase Google Login client id whitelist on the Firebase console (Credentials > Sign-In Methods > Google)!

Facebook Auth

  • Create a new app in the Facebook Developers page. The app can stay in sandbox mode.
  • Enable facebook login, and copy the App ID (FACEBOOK_APP_ID) and App Secret (FACEBOOK_SECRET) into the .env.local file's corresponding variables
  • In the Facebook Login admin, add the redirect url: https://yoursite/facebook-callback. It must be https, otherwise it won't work sadly!
  • Enable Facebook login in the Firebase console: Authentication > Sign-in method > Facebook.

Where to look

The most interesting part is in the Security folder.

There is a common Symfony security user, which is the same for Google and Facebook login. It holds the LinkProviderData and the UserRecord data so they are serialized to the session and are available on every request.

The login happens in the Guard classes, where linkProviderThroughAccessToken and linkProviderThroughIdToken are called. Before that, the official SDK-s are used for log in.

After a successful login, the UserProvider checks (verifies) the firebase ID token on every request, which originated from the linkProviderThrough* calls.

On logout, we try to revoke all refresh tokens in the LogoutSuccessHandler, that's all what Firebase can do sadly.

If the login was successful, the logged in User's data is dumped and it is possible to log out.

firebaseauth-example's People

Contributors

slaci avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.