-1

I am able to access users files by Impersonation.

When I call the classroom get method (https://developers.google.com/classroom/reference/rest/v1/courses/get) the drive Id folder is retrieved, with this fileId I want to call the drive api and get the file permissions BUT....... at this point I don't know who is the user (email) so I can impersonate it.

HINT: the classroom owner is not always the drive folder owner.

Is there a way to access the file without impersonating the user? (because I don't know it).

If I don't impersonate I get 404.

One one is to share the file to the service account but that would be too much there are many files.

Thanks in advance.

    try {
        let jwtClient = new google.auth.JWT({
            email : privatekey.client_email,
            key   : privatekey.private_key,
            scopes : [
                'https://www.googleapis.com/auth/drive.file',
                'https://www.googleapis.com/auth/drive',
                'https://www.googleapis.com/auth/drive.metadata',
                'https://www.googleapis.com/auth/drive.metadata.readonly',
                'https://www.googleapis.com/auth/drive.photos.readonly',
                'https://www.googleapis.com/auth/drive.readonly'
            ]
            //, subject : 'mail_to_impersonate@gmydomain.edu.pe'
        });
        //console.log(jwtClient);
        jwtClient.authorize(function (err, tokens) {
            if (err) {
              console.log(err);
              return;
            } else {
              console.log("Successfully connected!");
            }
        });
        let drive = google.drive({ version: 'v3', auth: jwtClient });
        let params = {
            fileId : 'the_classroom_teacherFolder.id'
        };
        drive.files.get(params, (err, res) => {
            if(err) {
                console.log('err:', err);
            } else {
                console.log('res:', res.data);
            }
        });
    } catch (error) {
        console.log(error);
    }

enter image description here

Diego
  • 326
  • 5
  • 13

1 Answers1

0
  • When you use courses.get the method returns you apart from the teacherFolder id also the ownerId
  • Now, you can use this ownerId as userId for userProfiles.get to retrieve the emailAddress
  • This is the email address you can use for impersonation
  • The course owner should always have access to the teacher folder of the corresponding course
ziganotschka
  • 25,866
  • 2
  • 16
  • 33
  • that's not always true I have some courses which the owner of the course is not even present in the file's permission list; others where the owner of the classroom is not the owner of the folder – Diego May 20 '20 at 18:27
  • I can only reproduce this situation for the case where you create a class programmatically assigning another user as the owner. In this case, indeed, trying to access the teacher folder will give a 404 until the teacher accepts the invitation to join the course from the UI. If your situation is different, can you explain please in detail how you created the course and changed permissions ownership if applicable. – ziganotschka May 21 '20 at 08:10