I updated the firebase database to version 9.2.0. Firebase uid used to be google: (google signin id), but now it doesn't match.
Before upgrade
Google Signin uid = 101672719428298324455
Firebase uid = google: 101672719428298324455
After update -
Google Signin uid = 101672719428298324455
Firebase uid = fcojpImyQWTHp02YzWYsRezShKP2
The Google uid is returned by other services, such as the classroom, so we need to use this as a uid to determine what user it is. We will update the users field to use uid for google login instead of firebase.
But then, how do we write security rules for auth using google signin uid with updated firebase? A specific use case for the rules is that the teacher can read the student report card. The teachers and student manuals provided by the google class for the class list correspond to google accounts, not firebase uid.
Below is the code that will be used to log in after the 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) {
AuthResult result = task.getResult();
FirebaseUser user = result.getUser();
Students for class load using google-classroom
"google:101379167706178411999": {
"profile" : {
"course" : {
"students" : {
"google:102942138935686001927" : {
"profile" : {
"name" : "student1 U."
}
},
"google:111992383609839990527" : {
"profile" : {
"name" : "student2 U."
}
}
}
},
"email" : "...",
"name" : "teacher User",
}
}
The teacher then uses google id identifiers to request the 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);