Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allowing to download a google doc only if the file is shared publicly

I know that when authorizing requests with OAuth, we can use several scopes to ask for a specific permission from the user. I want to ask for the permission for downloading files with publicly shared links (the user will actually provide this link).

However, the scopes listed here do not provide such an option. I do not want to get the permission for all the files and scare them.

Below is the code I am using. Any ideas? Do you think is it possible to get permission for the files with public links? Having access to the link shared can be utilized for this purpose?

private string[] Scopes = { DriveService.Scope.DriveFile};

private DriveService GetDriveServiceInstance()
{
    UserCredential credential;

    using (var stream = new FileStream("Services/credentials.json", FileMode.Open, FileAccess.Read))
    {
        string credPath = "token.json";
        credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
              GoogleClientSecrets.Load(stream).Secrets,
              Scopes,
              "user",
              CancellationToken.None,
              new FileDataStore(credPath, true)).Result;
          Console.WriteLine("Credential file saved to: " + credPath);
     }

     BaseClientService.Initializer bcs = new BaseClientService.Initializer();
     bcs.HttpClientInitializer = credential;
     bcs.ApplicationName = "synergy";

     DriveService service = new DriveService(bcs);
     return service;
    }
like image 670
renakre Avatar asked Oct 15 '22 15:10

renakre


1 Answers

The way oauth works with google drive is that you are requesting access to a users full drive account.

DriveService.Scope.DriveFile

enter image description here

Will give access to a users drive account but only access to the files which where opened or created with your client.

enter image description here

drive.readonly will give you full access to their full drive account to read and download files. There is no way to limit your access to only a directory, or only a group of files. its all or nothing.

Once you have access you can then search for the files you want as you now have access to their full account.

like image 186
DaImTo Avatar answered Oct 20 '22 10:10

DaImTo