Authentication to upload files in my drive using Google drive API client library for Java

只谈情不闲聊 提交于 2019-12-25 01:34:29

问题


I have spring+maven based java application having rest web service. For each call to this rest webservice, I want my application to upload a file to my google drive account.

I found this.

How can I authentication account before uploading in my application? Do I need Google OAuth2.0 for web application server application? or Authentication method in quick start guide for java will do for my application? I am new to OAuth.

Is there any complete guide on google drive authentication and using drive APIs?

What is the difference between google Oauth2.0 for installed app and google Oauth2.0 for web application server? When should I use each?


回答1:


If you've used the Authentication method in the Quickstart, that will do to have a authenticated request for uploading files.

To give a little description about Server Application and Authentication method in the Quickstarts:

Server Application Authentication are mostly paired with service accounts to authorize API requests, particularly when calling Cloud APIs to access project-based data rather than user-specific data. Web server applications can use service accounts in conjunction with user authorization.

This OAuth 2.0 flow is specifically for user authorization. It is designed for applications that can store confidential information and maintain state. A properly authorized web server application can access an API while the user interacts with the application or after the user has left the application.

OAuth 2.0 for Installed App

While some OAuth 2.0 Authentication like Javascript (Client-Side) is called the implicit grant flow. It is designed for applications that access APIs only while the user is present at the application. These applications are not able to store confidential information.

In this flow, your app opens a Google URL that uses query parameters to identify your app and the type of API access that the app requires. You can open the URL in the current browser window or a popup. The user can authenticate with Google and grant the requested permissions. Google then redirects the user back to your app. The redirect includes an access token, which your app verifies and then uses to make API requests.

Hope this helps.



来源:https://stackoverflow.com/questions/46723083/authentication-to-upload-files-in-my-drive-using-google-drive-api-client-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!