Sam Barnum
Sam Barnum

Reputation: 10714

Firebase custom OAuth authentication

FireBase appears to support OAuth-based authentication from Facebook, Twitter, Google, GitHub. What about a different OAuth provider? It would be great if there were a generic "OAuth" option where in addition to specifying an API Key and Secret you specified whatever other information was needed.

Is it possible to use FireBase's existing OAuth-based authentication modules without rolling my own custom OAuth authentication module for FireBase, by possibly forking from one of the "built-in" OAuth mechanisms? Which one is the most generic, if so?

Upvotes: 13

Views: 4247

Answers (2)

Oladayo Oyelade
Oladayo Oyelade

Reputation: 215

Firebase has 5 OAuth-based authentication, Facebook, Twitter, Google, GitHub and Custom Auth for now. Using Custom Authentication Firebase gives you complete control over user authentication by allowing you to authenticate using secure JSON Web Tokens (JWTs). So you can specify additional options to API Key and Secret. For example:

var logInAndThen = function(options) {
 var secret = '********************';
 var tokenGenerator = new FirebaseTokenGenerator(secret);
 var token = tokenGenerator.createToken(credentials[options.userType ||
 'admin'
};

Upvotes: 0

UnuSec
UnuSec

Reputation: 205

I also struggled for a while now with this, and here's how I've done it for my project. Run a node.js express server that will have the role to:

  1. get the req from your frontend app
  2. redirect user to oauth page
  3. return to node.js in case of success/error and compute the token needed for firebase in order to successfully login the user.
  4. res with a cookie containing this token and redirect the user back to frontend app to complete the process.

You will have to run the node server on a different vps in order for your app to work but you'll probably need it anyway if you have a bigger app that needs to run private stuff on the backend and not everything upfront.

Upvotes: 3

Related Questions