This is a Scala REST client for Firebase, which is based on Circe and is intended for services that don't require realtimeness of Firebase and just need to ger read/write access to the database in a convenient way.
- Fetching access token based on admin credentials aka service accounts;
- CRUD operations;
- Listing / adding / removing users [TBD].
One thing to always remember: in order to use this lib, you need a service account, and your app will always be accessing data on behalf of that service account. Kind of "admin access", so it's responsibility of your app to make sure that all the changes are legitimate.
Database operations:
import java.nio.file.{Files, Paths}
import io.github.mkotsur.firebase.auth.AdminCredentials
import io.github.mkotsur.firebase.rest.FirebaseClient
import io.circe.generic.auto._
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits._
val jsonKey: Array[Byte] = Files.readAllBytes(
Paths.get(getClass.getResource("/rest-client-scala-test-b1940c24c184.json").toURI)
)
val client = new FirebaseClient("rest-client-scala-test")
implicit val token = FirebaseClient.getToken(AdminCredentials(jsonKey)).get
// Reading a primitive
val ageFuture: Future[Option[Int]] = client.get[Int]("users/001/age")
// Reading an object as a case class
case class User(age: Int)
val userFuture: Future[Option[User]] = client.get[User]("users/001")
// more examples in ./src/test/scala/io/github/mkotsur/firebase/rest/FirebaseClientTest.scala
- The library adds BouncyCastle provider at runtime. Not necessarily a bad thing, but something to be aware of;
- There is a transitive dependency on Guava via
gitkitclient
; - Behavior of
FirebaseUsers.createUser
mimics gitkit behavior may be somewhat counter-intuitive. Please make sure to fully understand how it works before using in your app.
libraryDependencies = "io.github.mkotsur" %% "firebase-client-scala" % {latest-version}
The tests are executed against a firebase instance rest-client-scala-test
(configured in application-test.conf
).
There should be a user: [email protected] / 123qwe
.