How to use firebase authentication in couchbase sync gateway

310 views Asked by At

I'm developing an Android app. I have used firebase(email, password) authentication mechanism which is very secure and easy to implement. And as I want the data to be stored in our servers, I'm not using firebase storage. Couchbase sync gateway supports any open ID authentication. But I'm finding difficult integrating both. I have been searching more than a week. Anyone who have already used it. Could you please help me configuring.

1

There are 1 answers

0
function1983 On

For anyone looking for an answer, here are the steps to do it:

  • Firebase sends you an id_token (not signed). I assume you got to this part.
  • You convert this unsigned firebase id_token to a signed 3rd party oidc id_token. I use Keycloak running lightweight in a docker container for this job. Remember, you want the id_token, not access_token.

enter image description here

  • (Optional) you use Sync Gateway (SGW) ADMIN REST end point to create an user and assign the user to his/her appropriate [admin_channels].
  • SGW will accept your Keycloak signed oidc and give you a cookie when you hit its REST interface at the /_session end point. Make sure you put the id_token string in the Authorization header in the format "Bearer id_token_string........".

A few notes:

  • SGW will use the username (or create a new one if none existed) based on the "username_claim" keyword definition in your SGW.json config file. Use Keycloak client's mappers function if you want to customize your SGW user's name.
  • If you want to get the user's id_token without having to know the user's password then use the experimental token-exchange feature as mentioned here. enter link description here.

enter image description here

enter image description here

  • You use this cookie information to connect and sync data with couchbase via SGW as usual.

Couchbase has an article on how to implement implicit flow for oidc using syncgateway source