awslabs / aws-crt-nodejs

NodeJS bindings for the AWS Common Runtime.
Apache License 2.0
38 stars 24 forks source link

MqttConnection should refresh STS credentials for WSS connections on reconnect #423

Closed massi-ang closed 1 year ago

massi-ang commented 1 year ago

When using Cognito temporary credentials, the credentials expire after 1 hr. If the client gets disconnected after the credentials have expired, and anyway after 24hrs, any attempt to reconnect (which is handled automatically by the SDK) fail since the WSS URL is not valid anymore. Forcibly creating new connections every time the credentials expire is not optimal since the wss connection would be re-established every hour instead of the maximum 24 hrs.

The client should ensure that reconnections always succeed as long as the CredentialProvider passed to the configuration is able to provide valid credentials. This could be achieved by fetching the credentials from the credential provider at every reconnect and rebuild the WSS URL