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

There's no documentation on how to refresh/update the credentials. #460

Closed
raRaRa opened this issue Jan 23, 2024 · 8 comments
Closed

There's no documentation on how to refresh/update the credentials. #460

raRaRa opened this issue Jan 23, 2024 · 8 comments
Labels
documentation This is a problem with documentation. p3 This is a minor priority issue

Comments

@raRaRa
Copy link

raRaRa commented Jan 23, 2024

Hi. I'm using this library in a React project to have the ability to subscribe to events. I use the cognito identity method on the browser side to get credentials. It was very simple to do in v1 but now I'm trying to upgrade to v2. In v1 I could do updateWebSocketCredentials to update the credentials, but I can't find anything similar in v2.

I've tried various methods in v2, such as using new_with_websockets that accepts options:

let config = iot.AwsIotMqttConnectionConfigBuilder.new_with_websockets({
    region: awsConfiguration.region,
    service: "wss",
    credentials_provider: {
      getCredentialsAsync: async () => {
        const credentials: any = await getCredentialsAsync();
        if (credentials) {
          expiration = credentials.Expiration;
          return {
            accessKeyId: credentials.AccessKeyId,
            secretAccessKey: credentials.SecretKey,
            sessionToken: credentials.SessionToken,
            expiration: credentials.Expiration,
          };
        }
        return null;
      },
    },
  })

But that doesn't seem to work.

Is there no method to update the credentials when they expire? I found one React example that uses something called .with_credential_provider that doesn't seem to exist any longer.

.with_credential_provider(provider)

Any help would be appreciated.

Links

.with_credential_provider(provider)

@raRaRa raRaRa added documentation This is a problem with documentation. needs-triage This issue or PR still needs to be triaged. labels Jan 23, 2024
@bretambrose
Copy link
Contributor

with_credentials_provider hasn't gone anywhere as far as I know: https://github.com/awslabs/aws-crt-nodejs/blob/main/lib/browser/aws_iot.ts#L239

@jmklix
Copy link
Member

jmklix commented Jan 23, 2024

The .with_credential_provider(provider) option does still exist and the current sample in main still uses it.

And to refresh the credentials you just need to call refreshCredentials(). You can find that in the api docs here

@jmklix jmklix added p3 This is a minor priority issue response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 2 days. and removed needs-triage This issue or PR still needs to be triaged. labels Jan 23, 2024
@bretambrose
Copy link
Contributor

bretambrose commented Jan 23, 2024

There should be no need to refresh the credentials if the sample pattern is followed. A recurrent task does it for you:

https://github.com/aws/aws-iot-device-sdk-js-v2/blob/main/samples/browser/react_sample/src/PubSub.tsx#L49-L51

@raRaRa
Copy link
Author

raRaRa commented Jan 23, 2024

Thanks for the quick response @bretambrose

when I try to use .with_credential_provider(provider)

I get: Property 'with_credential_provider' does not exist on type 'AwsIotMqttConnectionConfigBuilder'.

I'm on aws-iot-device-sdk-v2 version 1.19.0 and aws-sdk 2.1541.0. Any clue what could be going on?

If I check the definition of with_endpoint, then I find it in /node_modules/aws-crt/dist/native/aws_iot.d.ts - but I see no presence of with_credential_provider in there.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 2 days. label Jan 23, 2024
@raRaRa
Copy link
Author

raRaRa commented Jan 23, 2024

Oh I figured out the issue. I forgot to set up the path in tsconfig.json. Sorry & thanks for the help. I highly recommend updating README with more details on browser usage.

@raRaRa raRaRa closed this as completed Jan 23, 2024
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@bretambrose
Copy link
Contributor

You're somehow ending up with the node source and not the browser source. If you're using typescript you can ok, you figured it out (https://github.com/aws/aws-iot-device-sdk-js-v2/blob/main/samples/browser/react_sample/tsconfig.json#L16)

@bretambrose
Copy link
Contributor

Oh I figured out the issue. I forgot to set up the path in tsconfig.json. Sorry & thanks for the help. I highly recommend updating README with more details on browser usage.

I agree, we should put a section in both aws-crt-nodejs and this repo as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation This is a problem with documentation. p3 This is a minor priority issue
Projects
None yet
Development

No branches or pull requests

3 participants