Google Drive iOS SDK Shared Folder - ios

I have an iOS app that loads PDF's for viewing. I want to allow the app to get the PDF's from a shared folder in google drive that is shared by some main admin account.
I have created a google drive project and set up OAuth for my app and am able to successfully list files using various queries with GTLQueryDrive.
The issue I am facing is related to the auth scope.
Lets say the google account hosting the files contains a shared folder: PDFAppFiles. We share this folder with 20 people.
Is there a way in my iOS app to request the auth scope for just that folder? I don't see this option listed: https://developers.google.com/drive/v2/web/scopes
Or, should I be approaching this problem a different way?

As the scopes page suggest, it authorizes your app to do what the requested scope is. This is a bit different from asking or setting permissions to a file or folder.
My recommended approach for the problem is to set permissions for every folder you want to control. The Share Files page of the Drive documentation details how you can do it.

Related

How to request a user to authorize an app to access a Google Drive file using the API

I have a web application and a Google Docs add-on that work together. The Docs add-on passes the web application the Google Drive file id of the Doc it's currently running in.
My web application needs to be able to be able to access/download the file content. I want the web application to use the drive.file scope, so that would require the user to authorize the web application access to the file in Google Drive.
I haven't found any APIs which let me request the user authorize the web app permission to a known file id. I could use the File Picker API, but then the user has to find the file in their Drive (annoying user experience given we already know the file and prone to errors).
Is there any way we can just redirect the user to a Google Drive URL where it asks them to confirm they want to open the file with my web app? Or to preselect the file in the File Picker?
I don't think you completely understand how scopes work.
The is no way to request permission for just a single file id. Scopes are all or nothing. If you have read only access then you have read only access to all of the files on the users drive account. Same for write access.
Now lets look at Scopes#Drive
https://www.googleapis.com/auth/drive.file See, edit, create, and delete only the specific Google Drive files you use with this app
If you request authorization of the user using the drive.file scope. It will allow your application to create files on the users drive account, and access those files which your application created and only those files.
So there is no way to get access to only a single file on a users drive account. If you want access to a file on the users account that wasn't created by your app then your going to have to use drive.readonly or drive. Depending upon if you want read or write access.

Use Google Drive from an app with a folder-limit (like Dropbox)

When I sign in an app via Dropbox, it says:
ABC would like access to its own folder, Apps › ABC (emphasis mine)
This is to sign, that the app, ABC, can access only its folder.
However, this folder is normally visible in the Dropbox directory and synced.
Is there a way to achieve this with Google Drive? It seems like using the app-specific data feature prevents users from using the directory in any way except the app. Granting a permission to use the whole Google Drive gives the app way too much permissions. Dropbox has this feature done well. IS there a way to do a sing-up process this way with Google Drive?
When your ABC app calls Google Drive APIs on behalf of a user, you're going to be using oAuth to authorize ABC. From Drive API v3 docs:
The details of the authorization process, or flow for OAuth 2.0 vary somewhat
depending on what kind of application you're writing. The following general process
applies to all application types:
When your application needs access to user data, it asks Google for a
particular scope of access.
Google displays a consent screen to the
user, asking them to authorize your application to request some of
their data.
Google Drive's resource authorization scheme includes a number of "permissive" scopes where your app can (for example) request access to the user's entire Drive and "narrow" scopes. In the latter case your app is restricted to certain Drive files and/or folders. In late 2018 Google announced Project Strobe that promised to tighten restrictions around "permissive" scopes for many Google services, including Drive. In May 2019, they rolled an updated policy for Drive APIs:
With this updated policy, we’ll limit the types of apps that have
broad access to content or data via Drive APIs. Apps should move to a
per-file user consent model, allowing users to more precisely
determine what files an app is allowed to access. This means that only
certain types of apps can request restricted scopes from consumer
Google accounts. As always, G Suite administrators are in control of
their users’ apps.
The more user-friendly, narrower scopes are tagged and referred to as Recommended throughout Google API docs. For Drive you have 3 recommended scopes :
https://www.googleapis.com/auth/drive.appfolder Allows access to the
Application Data folder
https://www.googleapis.com/auth/drive.file Per-file access to files
created or opened by the app. File authorization is granted on a
per-user basis and is revoked when the user deauthorizes the
app.
https://www.googleapis.com/auth/drive.install Special
scope used to let users approve installation of an app, and scope
needs to be requested
Your use case could fall into either drive.appfolder or drive.file scope. drive.appfolder works well if you're looking to store app-specific data that the user won't and shouldn't touch:
The application data folder is a special hidden folder that your app
can use to store application-specific data, such as configuration
files. The application data folder is automatically created when you
attempt to create a file in it. Use this folder to store any files
that the user shouldn't directly interact with. This folder is only
accessible by your application and its contents are hidden from the
user and from other Drive apps.
The application data folder is deleted when a user uninstalls your app from their
MyDrive. Users can also delete your app's data folder manually.
drive.file is applicable if your use case has to do with some data being created by your app on behalf of the user and the user or other users should be able to see/edit/share these documents. The issue with drive.file is that it only applies to "objects" your app creates. If your ABC app creates folder Foo and then creates some files within that folder, your app will be able to access the folder and these and only these files.
With drive.file there's no parent/child ownership semantics and no propagation of permissions from parent to child. The user (in their own browser without your app) could create more files in the Foo folder but your app won't be able to read them.
It's worth noting that drive.file is not granting access to a particular folder...but it sort of amounts to an equivalent end result for a to-be-created (by your app) folder or folders.
If you're looking for a way to get access to an existing folder, you may want to look into one of the Sensitive or Restricted scopes. Using one of these scopes requires your app to go through a security review.
Most apps only have permission to store data in the Application Data folder
There is more information about API permissions at About Authorization
The drive.file scope might work for some since it appears to give access to individual files that the user OK'd. How does the user OK a file? According to the post below, they would send a file from the Drive app to my app.
So, unlike Dropbox or OneDrive, Google Drive has only 2 types of permissions: Drive or Drive.File. Simple!

Google Drive - Access Drive without consent form (Username/password known)

I've been reading on Google Drive's API which seems straight-forward enough, but I'd like to use it a bit differently.
Instead of a client-side application, I need to be able to batch copy files in a given directory on a server to a specific Google Drive account which I have control over. To elaborate, I'm implementing a scan-to-email feature in which a user can scan a document on our copier which is then copied to that Google Drive account.
This is done for internal users, so the accounts would be generic and there would be no reasons to change the passwords. Is this possible at all?
I would recommend you go with a service account. Think of a service account as a user, a service account will have its own drive account. You will be able to upload the files to it, and your application wont be required to login as it will have the login built into it. You will not be able to login and see the files for this account via the web interface.
In order for the users to access the files again you have a few options.
You can then set the permissions on the files to allow the different users to access the files via there google drive accounts. Google drive api permissions
you could create your own interface and use files list to list the files that are currently stored on the service account.
Heads up:
You will at some point want to know how much space the service account drive has left. use about.get
Google has a number of client libs that can make doing all of this quite easy. but you haven't said what language you are planning on doing this in.
You could rely on the insert method of the "File" resource within the API. This will allow you to create a Google Drive File with the file type based on the scanned file. Refer to this document for examples and further assistance: https://developers.google.com/drive/v2/reference/files/insert#examples
https://developers.google.com/drive/web/manage-uploads

Storing static files on google drive in my rails app

In my rails app, I need to store my static assets (JS, CSS, images and downloads) on a storage service like S3, but I can not use S3 at the moment so I have searched and found google drive to be a good service.
Consider that in my app user can upload products and other user and pay then download the products.
I like to know that is there any problem for using google drive for these purposes?
Should I use google storage over google drive?
Does google drive provide secure and auto expire downloads link like S3?
You can use google drive through the google API.
We reserve a login through our apps account to act as the system and then share the requisite folders with that account.
That way you can then upload, download and pick up the files through the drive API using its account, without having to log in as different accounts each time.
I used the google_drive gem rather than the google one due to the hideousness of the security implementation.
Worth noting that the google drive gem now uses the google security implementation (since google shut off access by its previous method). You then have two options: a) Use a single account as described above.
b) Set up service account access.
Either should give you what you need.
You can use Google Drive for the storage of your static site files, although (I do not believe) Drive as a service has the same SLAs as Google Cloud Storage.
Google Cloud Storage is going to give you better SLAs and the expiring download links you are looking for (Cloud Storage Signed URLs).
To try and accomplish something similar in Drive, you would have to require each user to have a Google account, and programmatically set and revoke access, the only other access option is to make the share link available to everyone that has the link. (You might be able to circumvent this by copying the file around each time, but that would be ugly, and cumbersome).

iOS: Upload multiple files using Dropbox

All that I have researched integrating Dropbox iOS SDK requires logging in to authenticate/authenticate a user.
But this is what I want to accomplish
Use only one user account. (Without authorization)
Create a random public folder(in same account) and upload files to that folder.
Get the folder link.
It's basically sending generated files from the app to an account.
How can I possibly do this?
The API was designed with the intention that each user would link their own Dropbox account, in order to interact with their own files. However, it is technically possible to connect to just one account. The SDKs don't offer explicit support for it and we don't recommend doing so, for various technical and security reasons.
For example, any user who extracts the access token from your app will be able to read every file in the Dropbox account, delete everything, replace it, etc.
However if you did want to go this route, instead of kicking off the authorization flow, you would manually use an existing access token for your app. (Just be careful not to revoke it, e.g. via https://www.dropbox.com/account/applications.)

Resources