5

I am working on an assistant app for which I am writing a cloud function which must retrieve the current user data from Firebase database by using the user id. I am using firebase admin and I referred the docs for firebase admin where they've mentioned the way of retrieving user data by using user id but they haven't mentioned how to get the current user id. How do I get the currently signed in user id?

Mustafa Bhatkar
  • 335
  • 2
  • 13

1 Answers1

3

In order to get currently signed user id, you need to enable Account Linking in your AoG app.

In your AoG settings, enable Account linking with authorization code as grant type. Fill your client information and choose scopes.

Now when a user uses your app, it will ask for sign in, and on your AoG backend, you will be able to get authorization code.

Now using that authorization code you can retrieve the required user id and use that for your firebase admin.

You can find more info for Account linking here.

J Shubham
  • 609
  • 7
  • 21
  • I did the account linking like you said. In the auth url I pasted "https://accounts.google.com/o/oauth2/v2/auth" in auth url and "https://www.googleapis.com/oauth2/v4/token" in the token url. Is that correct? after that I was able to link my google account and then I tried to get the uid using the token still no success. would you please share the code for getting uid using authorization code? – Mustafa Bhatkar Aug 03 '17 at 19:20
  • Does your database contain uid of user's google account? What you can get from `auth_key` is email, name, uid of user's Google account. – J Shubham Aug 04 '17 at 14:19
  • No it does not has the uid of user's google account. I am using firebase database so it has the uid created by firebase. – Mustafa Bhatkar Aug 04 '17 at 14:48
  • Can you provide proper use of your db, like how are trying to relate users from your db to the user by google signin? To achieve this, you first need to have user's Google uid in your db. How a user identifies themselves for your application? Did they signin using google or you have your own way? – J Shubham Aug 04 '17 at 15:58
  • I have an android app in which I am using firebase authentication where a user can sign in using google or email. so when the user signs in, firebase creates uid. I use this id to store each users data in db. – Mustafa Bhatkar Aug 04 '17 at 16:51
  • `Account Linking` can not directly return that uid. But it seems, you are having the email for each user, so using account linking, you might get email of user from auth code. And using email, you can identify your firebase db users. Though I don't know how to "Get email from AoG account linking", but you can ask as different question or research. – J Shubham Aug 04 '17 at 17:34
  • Thank you for taking the time to reply. I will do some research to get the email from account linking. – Mustafa Bhatkar Aug 05 '17 at 08:51