Skip to content
This repository has been archived by the owner on Oct 22, 2021. It is now read-only.

How to authorize gdrive API #17

Closed
junaire opened this issue Aug 9, 2021 · 3 comments
Closed

How to authorize gdrive API #17

junaire opened this issue Aug 9, 2021 · 3 comments

Comments

@junaire
Copy link
Member

junaire commented Aug 9, 2021

Background

Recently I'm working on authorizing gdrive API in different ways. This is because I found we can't really authorize it simply via API key.(It succeed, but can't do things like Write, Delete)

Ways to authorize

After a long search, I found there are two ways to do this:

Oauth2

If we use this, users will have to copy a link from terminal, and paste a secret code from web.

JSON Web Token

Though Google claims that:

Your application must use OAuth 2.0 to authorize requests. No other authorization protocols are supported.

I still found another way to do this from StackOverFlow

We can generate a JSON file, and initialize the service like drive.NewService(ctx, option.WithCredentialsFile(jsonFilePath))

But there comes some problems: We can't access files created in go-storage, as they belong to the API account email (something like [email protected])

Maybe there is a way to solve this, see https://stackoverflow.com/questions/12211859/i-cant-see-the-files-and-folders-created-via-code-in-my-google-drive, but it looks very wired. :-(

Other problems

Now we choose our way to authorize service by using pairs, but it likes we don't have a protocol for Oauth.

Summary

  • Is it OK to let users copy the link and paste code to the terminal?( It makes hard to test
    - How to initialize Storager by using OAuth2?( I mean, like pairs.WithCredential("api:abcdefg")
  • Do we need support JSON Web Token?( Personally I don't want to do this...
@Xuanwo
Copy link
Contributor

Xuanwo commented Aug 10, 2021

gcs uses oauth2 too: https://github.com/beyondstorage/go-service-gcs/blob/master/utils.go#L99-L116

Maybe we can use the already authorized token to send API? Let the user decide how to generate the token files. (We can add another tool to help the user finish the job.)

GitHub
Google Cloud Storage support for go-storage. Contribute to beyondstorage/go-service-gcs development by creating an account on GitHub.

@junaire
Copy link
Member Author

junaire commented Aug 10, 2021

gcs uses oauth2 too: https://github.com/beyondstorage/go-service-gcs/blob/master/utils.go#L99-L116

Sorry but I don't realize we already have examples to do this. Let's update gdrive with what we did in gcs

GitHub
Google Cloud Storage support for go-storage. Contribute to beyondstorage/go-service-gcs development by creating an account on GitHub.

@Xuanwo
Copy link
Contributor

Xuanwo commented Aug 10, 2021

Fixed in #18

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants