Skip to content
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

TypeError: Cannot read property 'accessToken' of undefined #52

Closed
NathanHazout opened this issue Sep 4, 2019 · 7 comments
Closed

TypeError: Cannot read property 'accessToken' of undefined #52

NathanHazout opened this issue Sep 4, 2019 · 7 comments

Comments

@NathanHazout
Copy link

First of all, I need a confirmation. If I use service credentials stored in ~/.bluemix/cos_credentials per the documentation, then I don't need to pass anything to the constructor right?

I've created the following file ~/.bluemix/cos_credentials (redacted):

{
  "apikey": "REMOVED REMOVED",
  "endpoints": "https://control.cloud-object-storage.cloud.ibm.com/v2/endpoints",
  "iam_apikey_description": "Auto-generated for key ...",
  "iam_apikey_name": "Service credentials-1",
  "iam_role_crn": "crn:v1:bluemix:public:iam::::serviceRole:Manager",
  "iam_serviceid_crn": "crn:v1:bluemix:public:iam-identity::a/SOMETHING-SOMETHING",
  "resource_instance_id": "crn:v1:bluemix:public:cloud-object-storage:global:a/SOMETHING-SOMETHING::"
}

The empty constructor did not throw any error. Then I tried to create a bucket per the sample:

console.log(`Creating bucket ${bucket}`);
        let result = await client.createBucket({
            Bucket: bucket
        }).promise();
        console.log(result.response);

And I get:
TypeError: Cannot read property 'accessToken' of undefined

What is accessToken? It is not defined either in the cos_credentials nor in the constructor options...

@kellerbr-ibm
Copy link
Contributor

You'll still need an endpoint which you can get either from the endpoints JSON file linked in the cos_credentials file or from the Cloud Console on the page for your bucket.

IAM authentication uses refreshable tokens for short-lived authentication so that in the event of a hijacked request the access window is limited. It sounds like an invalid response was given for the authentication request, but that is generally handled and returned back with an error saying as much. In this case it looks like it accepted an invalid token which contained no auth information.

May I ask for a stack trace if you have one?

You may be able to fix this by adding the following to your constructor.

const client = new COS.S3({
   endpoint: '<endpoint>',
   ibmAuthEndpoint: 'https://iam.cloud.ibm.com/identity/token'
});

If not, let me know and I can look into it further.

@dragos-cojocari-ibm
Copy link

I think the root cause for this issue is #55

@paul-carron
Copy link
Contributor

Duplicate of #55

@kellerbr-ibm
Copy link
Contributor

I've replicated the issue and a fix will be included in the upcoming October release.

@kellerbr-ibm
Copy link
Contributor

@nasht00 The issue should be resolve in the new 1.5.4 release. If possible would you be able to verify it and close?

@NathanHazout
Copy link
Author

Truth is this happened a while ago, I'm not sure even sure I ended up using it.
I'll try to look for it.

@rtveitch
Copy link
Member

Closing due to inactivity. If you continue to experience this error please let us know and we'll re-open.

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

No branches or pull requests

5 participants