0

is there a way to generate or get a long living authentication token for Drive REST APIs?

I am interested in pure REST API calls (no SDKs) for a server-to-server scenario for communication with a single Drive (no access to users' Drives). If I didn't missed something, this is supported: https://developers.google.com/identity/protocols/OAuth2ServiceAccount

However, the generated access token is valid for an hour, which I think is quite an overhead.

For similar functionality Dropbox provides long living access token. Is this somehow possible with Drive?

pinoyyid
  • 21,499
  • 14
  • 64
  • 115
MerlinBG
  • 338
  • 1
  • 5
  • 16

1 Answers1

1

Yes. It's all quite straightforward. It's all in the terminology.

To access a resource, your app needs an Access Token. These always expire after 60 minutes (although Google reserves the right to change that in the future). When you acquire an Access Token, it will come with its expiration time.

To acquire an Access Token, your app can first request a long-lived Refresh Token. A Refresh Token is (almost) perpetual, although events such as the user changing his password will cause it to expire. Your app can Post the Refresh Token to an endpoint which will return you an Access Token without any user involvement.

I've spelt out the steps at How do I authorise an app (web or installed) without user intervention? (canonical ?)

An alternative approach is to create a Service Account which is an account "owned" by your app. Your app can then use two-legged auth to provide access. See https://developers.google.com/identity/protocols/OAuth2ServiceAccount

Community
  • 1
  • 1
pinoyyid
  • 21,499
  • 14
  • 64
  • 115
  • Great, thanks a lot! This seems to be exactly what I need! Where can I configure step 3 - set https://developers.google.com/oauthplayground as callback URL? The video seems to be a bit outdated. – MerlinBG Mar 16 '17 at 13:47
  • https://console.developers.google.com/apis/credentials/oauthclient?project=XXXXXXX Where XXXXXX is the registred project name, or just start at https://console.developers.google.com/apis and go from there. I'll update the linked answer with the updated URLs – pinoyyid Mar 16 '17 at 14:32
  • Found it :) Awesomeness!! Thanks! – MerlinBG Mar 16 '17 at 18:16