Only the region property in the configuration object is mandatory.
HTTP requests
The way this module works is by configuring an HTTP interceptor which handles everything for you. If you use a baseUrl, you should use the AWSHttpClient, if not, you can just use the Angular HttpClient.
// We get temporary credentials back from the API, you can simply pass them through the the service and it will be taken care of automatically
returnthis.awsHttpService.setCognitoCredentials({
Token:result.Token,
IdentityId:result.IdentityId
});
})
.subscribe(()=>{
// Navigate to the home page
});
}
}
After the authentication request, we call the AWSHttpService.setCognitoCredentials which will handle the token exchange for you.
Refresh
A refreshing mechanism is built-in. However, because the library is not aware of the API endpoints that should be used or what data is returned, we have to provide some extra functions.
The AWSHttpService.refresh method accepts a function which returns a HttpRequest object which determines which endpoint should be made in order to refresh the token. Whenever the current token expires, that function is called and the HttpRequest is executed.
Because the library is not aware of what the response of the refresh request looks like, a second function has to be provided in the AWSHttpService.onRefresh call. This function accepts the response of the refresh API call and should return an object which determines the new cognito credentials.
It can happen that the request which is made to refresh the tokens fails. In order to handle this error, an extra method AWSHttpService.onRefreshError can be used. This function will return the error of the request.