Google Drive API username + password authenticatio

2019-04-08 14:12发布

问题:

I'm developing an application where Google Drive will be used to manage some documents. The idea is to create a document with some initial template data and provide the users access by adding them as collaborators of the document.

I'm familiar with the OAuth authentication process, I used it in another part of the system to manage the users Calendar...

But in this case these documents will be stored in a generic account of the company, so I can't have the approval prompt for authentication, since users won't have the password of the account.

I'd like to directly authenticate in this account, could be with the username and password hardcoded in the Java code.

Problem that this method of authentication was depreacated and I didn't found a relpacement.

Any ideas?

Thanks in advance, Phillip

回答1:

There are 2 ways that comes to mind:

  1. Service accounts: best suited for server side OAuth with traditional backend
  2. Regular Account owned by the application : similar to the process already in place for client side Oauth that you are already familiar with; Auth, store the refresh, ask new token if the AuthCode is expired, and so on.

I personally use and prefer the second solution more as I feel is more flexible to adapt in the future for Oauth Client Side get the tokens and use them server side.