0

I have a Google service account that my server application can authenticate to. It works fine. I followed this: https://developers.google.com/identity/protocols/OAuth2ServiceAccount#authorizingrequests.

I want the users of my application to upload files to a Google Drive folder. My service account as access to this drive. I want to generate, on the server, a token that I can forward to my users (in the browser) so they can upload a file to the Drive's folder. (https://developers.google.com/identity/protocols/OAuth2ServiceAccount#authorizingrequests)

Is there a way I can generate a token for a one time upload or that would last a very limited period of time?

Note: I currently have a working prototype where I use a signed URL that my user's browser can post to (https://cloud.google.com/storage/docs/xml-api/post-object) that uploads in a Google Storage bucket.

David
  • 1,101
  • 5
  • 19
  • 38
  • I think your probably going to have to generate your own token, its not going to be anything google can do for you. – Linda Lawton - DaImTo Apr 08 '16 at 13:08
  • I'm only trying to avoid uploading the file to my server first and then uploading the file in Google Drive from my server. – David Apr 08 '16 at 13:10
  • 1
    I just found this: http://stackoverflow.com/questions/32992969/downloading-file-with-service-account-using-signed-url-in-google-cloud-storage Where you answered :P and it seems I can't do this kind of thing. – David Apr 08 '16 at 13:11
  • No I don't really think you can, only way it would work would be in a client sided application which service accounts don't really work client sided. Unless you can figure out how to send the access token created by the service account to the client sided application and have them use that to upload, would kind of depend on what type of application you are createing here. – Linda Lawton - DaImTo Apr 08 '16 at 13:13

1 Answers1

0

"Is there a way I can generate a token ... that would last a very limited period of time?"

You could have a cron type task on your server that is creating tokens, say every minute, and then storing them. When your client needs a token, give it one which is near to its expiration time.

pinoyyid
  • 21,499
  • 14
  • 64
  • 115