Can you use the Drive API to share a file in Google Drive to an oath2 subject rather than email address?

22 Views Asked by At

So I have a "sign in with google" button on my site that uses the oauth2 flow to identity the user, but we don't request their email address as we don't strictly need it. This works fine and I can use the returned subject to identify users.

I would now like to create a file in a drive, and share it with this logged in user. I can create the file ok, but sharing it seems to require the users email.

Can I share a file to an external subject somehow, or will I need to ask them for an email address, either as an oauth2 scope or later once they have signed in?

The docs here:

https://developers.google.com/drive/api/guides/manage-sharing#create-permission

Say "When you create a permission where type=user or type=group, you must also provide an emailAddress to tie the specific user or group to the permission."

So maybe this is not possible?

1

There are 1 best solutions below

2
Linda Lawton - DaImTo On

If you have access to the users google drive account you can do an about.get

It returns an about object which contains a user object which ...

{
  "displayName": string,
  "kind": string,
  "me": boolean,
  "permissionId": string,
  "emailAddress": string,
  "photoLink": string
}

Gives you the users email address.