14
Aug

How the Admin SDK Works with Java, Cloud Auth, & More! #AskFirebase


JEN PERSON: All right. Can you scroll back to
the top of it again? I know what I’m going to say. I got this. Hey, all you
Firebase developers. Welcome to another
episode of “Ask Firebase,” and I am here with
Hiranya, and we’re going to be answering your
burning Firebase questions. I’m so excited that
you’re on the show today because you work with
one of my favorite products around here. Why don’t you tell us a little
bit about what you do here? HIRANYA JAYATHILAKA: Yeah, I’m
in charge of Firebase Admin SDK offerings. That’s our SDKs for the
server-side environments, and we have four
different flavors of it, starting from the
Node.js Admin SDK, which is our most widely
used and probably the most mature and most
feature-rich as the admin SDK offering. And we also have Java, Python,
and since recently, Go, in the SDKs. JEN PERSON: Yeah, that’s right. We just added Go, as well. Really excited about
that, and people might know the Admin
SDK if they use Cloud Functions for Firebase. HIRANYA JAYATHILAKA: Yeah. In fact, the functions
SDK is probably one reason why Node
Admin SDK is so popular, because it’s based
off of Node Admin SDK. So whenever you are doing
a database call or a user management operation
in a function, you’re actually using
the Node.js Admin SDK. JEN PERSON: The more you know. Actually, why I
wanted you to come on is because whenever I have
questions about the Admin SDK, I ping you, and I know you
have a lot on your plate, but you always get back to
me right away with an answer. And I figured, why not share
that knowledge with the rest of the Firebase community? So glad to have you come
out and share your knowledge with the larger group. HIRANYA JAYATHILAKA: Certainly. JEN PERSON: So, let’s get into
some questions about the Admin SDK. First question comes to
us from Stack Overflow. I am creating a
simple web portal using Firebase cloud
authentication. One user is an admin who will
create other normal users and hand over the credentials
to the normal user, so they’re using the
Admin SDK for that. Now I want that admin
to have the option to reset the password
for a normal user. How can they achieve this? HIRANYA JAYATHILAKA: If you
look into the alt and user management APIs
that are currently available in the Admin
SDKs, one feature that we support out of
the box is just this, just resetting password
of an existing user. This comes up very often
in server-side use cases. There’s an admin and
a non-admin user, and the admin needs to
provision user accounts, as well as do certain updates
and mutations on the user data, like resetting the
user’s password is one of the most common
scenarios in that respect. And what you would do is, if you
are programming in, let’s say, Node.js, you would call
admin.alt.updateuser, and just pass the new
password in, and that gets propagated to all the back
end systems in Firebase then. JEN PERSON: Sweet. I will also link us
to the documentations so if they want
to find out more, you can check out all the
different options you have with auth for the Admin SDK. All right, what else we got? Oh, this one. So I really like this question. This is one I
specifically asked you about because there was an
update to the Java Admin SDK, and we had a user on
Stack Overflow that noticed that they
weren’t getting calls to the real-time database when
they were trying to read in it. It appeared that everything
else was happening, but those calls
weren’t being made. But when you think about
it a little deeper, there was something
else going on. So what is it about
how the Java Admin SDK works that might impact
what that experience is like if users are testing things? HIRANYA JAYATHILAKA:
Right, this is actually one of the fundamental
differences in how an Android app would work and how a
regular Java application would run in the JVM. So JVM, it comes up, and then
it starts the application’s main thread, and it
does some operations, and when the main thread exits,
the whole JVM exits, provided it hasn’t spawned
any other threads. So let’s say you
start your application and you do a Firebase.– you call initialize
app, and then you start a database connection,
and then you start listener. You think you are waiting
for the events to fire, but what’s happening, actually,
is the main thread exits, and it takes the whole JVM down. So before any events could
fire, any real-time events are actually delivered
from Firebase back to into your application,
your port program exits. So what you have to do is
actually tell the application to, hey, register
this event listener and wait for things to happen. And there are different
ways to deal with this. The simplest way is to
just tell the main thread to just go to sleep,
just wait, or you can use more advanced
concurrent programming constructs like semaphores
wait notify constructs. And there are all sorts of cool,
fun things you can do in Java and threads to just implement
this bit of synchronization. JEN PERSON: Right, and I would
say that this is certainly a feature and not a bug, because
it wouldn’t be a good idea to block the main thread
for something like this. HIRANYA JAYATHILAKA: Yeah, so
you can actually argue for– I’ve seen arguments for
both sides of this story. Some users certainly
prefer if the SDK can just wait on behalf of them, but the
philosophy that we’ve followed is if the Admin SDK
starts a thread, it will also take care of
cleaning up that thread. And any thread
that the SDK starts will be actually started
as what is called a daemon, and daemons will not prevent
the JVM from exiting early. And this is actually
important if you’re running your application
in environments like Appen generator, which
is thread constrained. [INAUDIBLE] has other
constraints on threads. You absolutely do not want
threads just hanging out. You want the whole thing to
exit as soon as possible, so that’s why the Admin
SDK is designed that way. Unfortunately, it has
this other ramification. If you’re running this
on your own server, if you’re quickly trying
to try something out, it has this be a behavior. To the naked eye, it seems like
the application just stopped before anything happened. JEN PERSON: Right. I feel very lucky that I get to
be surrounded by so many people that I can just turn and ask
when these things come up. But I think that is really great
information about how the Admin SDK works with Java, and
super helpful, so thank you. HIRANYA JAYATHILAKA: Of course. JEN PERSON: Well, thanks so
much for coming on and answering some Firebase questions. And as I start to collect
some more– hint, hint– when you have some questions
about the Admin SDK, make sure you put
them on social media and tag them with “Ask
Firebase,” so I can have Hiranya back on the show. Any of your other
questions that come along, make sure you send them our way. Thanks. HIRANYA JAYATHILAKA:
Thanks for having me. [MUSIC PLAYING] JEN PERSON: All right. Let’s do it.

Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

14 Comments

  • Burak Gavas says:

    I cant help watching when I see u on the preview screen Jen. Keep it up 🙂

  • Jerry hanks says:

    Jen Weldon for all the works you are doing here, I love you for that, hope to meet you one day.

  • John Aran says:

    I need realtime database with PostgreSQL and Golang

  • Shubham Deshpande says:

    Ok can someone help me, I started C now, would like to go up, what do I do now? Btw m in engineering 1st year 2nd sem!

  • aeon aztec says:

    Go firebases!!!

  • Qalqi says:

    Cool tattoo! Cover some tips on angularfire2 universal /isomorphic application #askfirebase

  • Metsuryu says:

    #AskFirebase

    In the Cloud Functions documentation it says:

    "The current Node.js version running in Cloud Functions is Node v6.11.5"

    So I assume it would be best to have that node version in my local environment, so that it will behave like it does on the cloud.

    But what if I want to use the latest node releases? Is there a way to make the local cloud functions emulator use Node v6.11.5, but use the latest versions for everything else?
    Or is it OK to just use the latest version of node even for the cloud functions emulator?

  • Angus Tay says:

    #AskFirebase
    I'm working with Firebase, Google Cloud Natural Language Processing and Android.
    How do I use my firebase auth (user credential) in the Google Cloud NL (using service account now, thinking to replace with firebase user credential)?
    My app is using firebase auth and firestore

  • SqualoWave says:

    Please support php. I know it's not in fashion, i'd rather not use it myself, but it is the defacto web language.

  • Juan Guillermo Gomez Torres says:

    For the second question, it is possible to use rxjava

  • Thirunayan Dinesh says:

    #AskFirebase Can i retrieve collections from cloud firestore??

  • king says:

    I need firebase server admin for java 1.6 so which sdk version is compatible with java 1.6

  • Deven Chavda says:

    can I use firebase for java desktop application or in Java? I'm not asking about android because I'm using it in android.
    Can anyone help me out I want to learn firebase with java applications so?

  • benton202 says:

    so this the guy that is responsible for just BARELY providing documentation on firebase admin SDK….

Leave a Reply

Your email address will not be published. Required fields are marked *