0

I am using @Chime-sdk and @Angular-12 using AWS STS token, which one will expired after 15 minutes. After Expired STS token AWS call refresh method so I used refresh() method to call my back-end api for new token then I re-assign all credentials, till now it's working good.

But it can't retry last api or request after completed refresh method execution. below attached my code:

this._aws.credentials.refresh = (() => {
      this.exampleApiService.getToken().toPromise()
        .then((response: any) => {
          this._aws.credentials.accessKeyId = response.accessKeyId;
          this._aws.credentials.secretAccessKey = response.secretAccessKey
          this._aws.credentials.sessionToken = response.sessionToken;
          this._aws.credentials.expireTime = response.expireTime;
          this._aws.credentials.expired = false;
          this.setChimeClient();

        }).catch(error => {
          console.log(error)
        });
    })

So How can i retry or recall my last last api call or request ?

MD Ashik
  • 9,117
  • 10
  • 52
  • 59

1 Answers1

0

After trying multiple way, I get solution that's was to easy.

Chime pass a callBack function to refresh function so after credential set if we call, callBack function then Chime re-initiate last API call or process.

if we fail to generate refresh or new token then we can pass error in callBack function as param. below added example code.

this._aws.credentials.refresh = ((callback) => {
      this.exampleApiService.getToken().toPromise()
        .then((response: any) => {
          this._aws.credentials.accessKeyId = response.accessKeyId;
          this._aws.credentials.secretAccessKey = response.secretAccessKey
          this._aws.credentials.sessionToken = response.sessionToken;
          this._aws.credentials.expireTime = response.expireTime;
          this._aws.credentials.expired = false;
          this.setChimeClient();
          callback();
        }).catch(error => {
          console.log(error)
        });
    })
MD Ashik
  • 9,117
  • 10
  • 52
  • 59