Skip to content

Authentication(user consent) using Google Cloud Storage API #2331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
laiyhman opened this issue May 25, 2017 · 3 comments
Closed

Authentication(user consent) using Google Cloud Storage API #2331

laiyhman opened this issue May 25, 2017 · 3 comments
Assignees
Labels
api: storage Issues related to the Cloud Storage API. core type: question Request for information or clarification. Not an issue.

Comments

@laiyhman
Copy link

Hi,
We have an application that need to get user consent(OAuth2) to access user's bucket and was looking at this library https://googlecloudplatform.github.io/google-cloud-node/#/docs/storage/1.1.0/storage.
However i can't find how i can set the access token with this library, can you point me to the right direction?

@stephenplusplus
Copy link
Contributor

Hello! We currently don't have official support for this across all of our APIs (follow along with #1346 to track support).

For Storage, you should be able to use a request interceptor, such as:

var gcs = require('@google-cloud/storage')(...)

gcs.interceptors.push({
  request: function(reqOpts) {
    reqOpts.headers.authorization = `Bearer ${yourToken}`
    return reqOpts
  }
})

gcs.getBuckets(...) // "yourToken" was used

@stephenplusplus stephenplusplus added api: storage Issues related to the Cloud Storage API. core type: question Request for information or clarification. Not an issue. labels May 25, 2017
@laiyhman
Copy link
Author

Hi,

Following your suggestion, i'm getting the following error

TypeError: Cannot set property 'authorization' of undefined
at Object.request (C:\Development\git\git.mbww.com\datapoint\dat-file-delivery\delivery-handlers\gcs.delivery.js:50:51)
at Storage.Service.request_ (C:\Development\git\git.mbww.com\datapoint\dat-file-delivery\node_modules@google-cloud\common\src\service.js:148:27)
at Storage.Service.request (C:\Development\git\git.mbww.com\datapoint\dat-file-delivery\node_modules@google-cloud\common\src\service.js:172:30)
at Storage.getBuckets [as getBuckets_] (C:\Development\git\git.mbww.com\datapoint\dat-file-delivery\node_modules@google-cloud\storage\src\index.js:364:8)
at makeRequest (C:\Development\git\git.mbww.com\datapoint\dat-file-delivery\node_modules@google-cloud\common\src\paginator.js:223:5)
at DestroyableTransform. (C:\Development\git\git.mbww.com\datapoint\dat-file-delivery\node_modules@google-cloud\common\src\paginator.js:219:5)
at DestroyableTransform.g (events.js:292:16)
at emitOne (events.js:96:13)
at DestroyableTransform.emit (events.js:188:7)
at DestroyableTransform.obj.(anonymous function) [as read] (C:\Development\git\git.mbww.com\datapoint\dat-file-delivery\node_modules\stubs\index.js:28:22)
at DestroyableTransform.Readable.read (C:\Development\git\git.mbww.com\datapoint\dat-file-delivery\node_modules\readable-stream\lib_stream_readable.js:365:10)
at resume
(C:\Development\git\git.mbww.com\datapoint\dat-file-delivery\node_modules\readable-stream\lib_stream_readable.js:716:12)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickDomainCallback (internal/process/next_tick.js:128:9)
at Timeout.Module.runMain [as _onTimeout] (module.js:606:11)
at ontimeout (timers.js:386:14)

@stephenplusplus
Copy link
Contributor

I'm sorry, I was incorrect with that solution. It turns out we do the authentication after those request interceptor functions run. That would mean regardless of what you set, it would be overwritten by the automatically-managed token that our library fetches.

So for now, we still don't support this type of use. Please subscribe to #1346 for any updates on the development.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the Cloud Storage API. core type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

2 participants