IBM / ibm-cos-sdk-js

ibm-cos-sdk-js
Apache License 2.0
38 stars 20 forks source link

Authentication with access token #85

Closed bourdakos1 closed 3 years ago

bourdakos1 commented 3 years ago

Is it possible to use this sdk with only a service instance ID and an access token? (no api key)

nglange commented 3 years ago

That's a good question. It is possible with the Java SDK, which makes me think it should be possible. I'll take a look and provide an update.

nglange commented 3 years ago

Yeah, looks like it's as easy as just providing a token instead of an apiKeyId during client creation. Here's the relevant code: https://github.com/IBM/ibm-cos-sdk-js/blob/5d776bcb86f5b715cf0422107fdfc467eb0eb39e/lib/iam/token_manager.js#L76

bourdakos1 commented 3 years ago

Thanks, I wasn't able to get token working, but I was able to pass a tokenManager:

new COS.S3({
  endpoint: "https://s3.us.cloud-object-storage.appdomain.cloud",
  serviceInstanceId: "...",
  // @ts-ignore
  tokenManager: {
    getToken: () => ({
      accessToken: token,
    }),
  },
});

Neither token or tokenManager are part of the typedefs

IBMeric commented 3 years ago

Has your issue been resolved?

bourdakos1 commented 3 years ago

Not exactly, I was able to do a work around, but there doesn’t seem to be an official way to do this?

IBMeric commented 3 years ago

@bourdakos1 Your resolution would be the "official" one I would suggest. There currently is no support for supplying a pre-fetched IAM token. For cases like this, we suggest extending the token manager with the behavior you are looking for. Also, re: typedefs, I've opened an internal ticket.

If this cover everything, please close this as resolved.

bourdakos1 commented 3 years ago

okay great, yea the typedef fix would cover everything thanks :)