AWS-Amplify API is always returning 403 unauthorized with angular
See original GitHub issueAWS-Amplify using API.get() with angular to call Serverless API with IAM authentication is always returning 403 unauthorized, even though that I have followed all the instructions posted on GitHub and stackoverfolw,
here is my code for using api.get:
` async testApiCall() { const user = await Auth.currentAuthenticatedUser(); const token = user.signInUserSession.idToken.jwtToken;
const request = {
headers: {
Authorization: token
}
};
var response = await API.post('orders', '/orders', request)
.catch(error => {
alert('error' + error);
});
alert(response);
document.getElementById('output-container').innerHTML = JSON.stringify(response);
}`
and here is my config.ts:
export default { MAX_ATTACHMENT_SIZE: 5000000, s3: { REGION: "eu-central-1", BUCKET: "xxxxxx" }, apiGateway: { REGION: "eu-central-1", URL: "xxxxxxxx" }, cognito: { REGION: "eu-central-1", USER_POOL_ID: "xxxxxxxxxxxxxxxxx", APP_CLIENT_ID: "xxxxxxxxxxxxxxxxx", IDENTITY_POOL_ID: "xxxxxxxxxxxxxxxxx" } };
And here is what I have in environment.ts:
export const environment = { production: true, amplify: { Auth: { identityPoolId: 'xxxxxxxxxxx', region: 'eu-central-1', userPoolId: 'xxxxxxxxx', userPoolWebClientId: 'xxxxxxxxxxx' }, API: { endpoints: [ { name: "orders", endpoint: "xxxxxxxxx" } ] } } };
any suggestions please?
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (3 by maintainers)
Top GitHub Comments
@khaledshamat if you are using IAM authentication, and as I could assume based on your config, you are using the Cognito Federated Identity Pool service right? In that case, you shouldn’t do the following:
The amplify library will fetch the credentials internally and sign the request. Can you also open the debug mode by putting
window.LOG_LEVEL='DEBUG'
to get more info?This issue has been automatically locked since there hasn’t been any recent activity after it was closed. Please open a new issue for related bugs.
Looking for a help forum? We recommend joining the Amplify Community Discord server
*-help
channels or Discussions for those types of questions.