android - google signin uid & firebase uid don't match after firebase upgrade to 9.2.0 -


i upgraded firebase database version 9.2.0. firebase uid used google:(google signin id), but, doesn't match now.

before upgrade -

google signin uid = 101672719428298324455

firebase uid = google:101672719428298324455

after upgrade -

google signin uid = 101672719428298324455

firebase uid = fcojpimyqwthp02yzwysrezshkp2

the google uid returned other services such classroom, so, need use uid tell user is. update users field use google sign-in uid instead of firebase one.

but, then, how write security rules auth using google signin uid upgraded firebase? specific use case rules teacher can read student's report card. teacher , student uids provided google classroom class roster match google sign-in uids, not firebase uid.

below the code being used login after upgrade -

firebaseauth auth = firebaseauth.getinstance();         authcredential credential = googleauthprovider.getcredential(token, secret);         auth.signinwithcredential(credential).addoncompletelistener(new oncompletelistener<authresult>() {             @override             public void oncomplete(@nonnull task<authresult> task) {                  // authenticated payload authdata                 authresult result = task.getresult();                 firebaseuser user = result.getuser(); 

the students class loaded using google-classroom

"google:101379167706178411999": {   "profile" : {     "course" : {       "students" : {         "google:102942138935686001927" : {           "profile" : {             "name" : "student1 u."           }         },         "google:111992383609839990527" : {           "profile" : {             "name" : "student2 u."           }         }       }     },     "email" : "...",     "name" : "teacher user",   } } 

then, teacher uses google signin ids query student -

 queryref = mfirebase.child("users").child(uid).child("profile").child("course").child("students").orderbykey();         listlistener = queryref.addchildeventlistener(new childeventlistener() {             @override             public void onchildadded(datasnapshot snapshot, string previouschild) {                 log.d("dashboarddatahandler", "attaching listener to: " + snapshot.getkey());                 final string key = snapshot.getkey();                 addorupdateuserprofile(snapshot, key); 

for existing users, uid not change when import existing project new firebase console (https://console.firebase.google.com). users created after importing project new uid format. intentional: should not rely on inherent structure in uid firebase provides.

if want know google id user signed in firebase authentication google account, can currentuser field. documentation on accessing user's provider-specific profile information:

to profile information retrieved sign-in providers linked user, use getproviderdata method. example:

firebaseuser user = firebaseauth.getinstance().getcurrentuser(); if (user != null) {     (userinfo profile : user.getproviderdata()) {         // id of provider (ex: google.com)         string providerid = profile.getproviderid();          // uid specific provider         string uid = profile.getuid();          // name, email address, , profile photo url         string name = profile.getdisplayname();         string email = profile.getemail();         uri photourl = profile.getphotourl();     }; } 

you'll note getproviderdata returns list of userinfo objects nowadays, since single user account can have multiple linked providers.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -