amazon-archives / aws-cognito-angular-quickstart

An Angular(v5)-based QuickStart single-page app utilizing Amazon Cognito, S3, and DynamoDB (Serverless architecture)
https://cognito.budilov.com
Apache License 2.0
689 stars 304 forks source link

STS token not retrieved and getting cognito-identity 400 error???? #113

Closed soacs closed 6 years ago

soacs commented 6 years ago

I took your awslabs/aws-cognito-angular2-quickstart example installed on my desktop and I am getting the following error. Seems like USERPOOL working but STS not giving me the cognitoId. Your online sample shows the cognitoId value in myprofile - but mine does not. I introduced lots of logging to see what is going on. see log below. I am getting the erro rin log:

UserLoginService: Successfully set the AWS credentials - err = CredentialsError: Missing credentials in config

export const environment = { production: false, region: 'us-east-1', identityPoolId: 'us-east-1:bc9425dc-ba77-4f39-9ada-0ce48fb122cb', userPoolId: 'us-east-1_x3YEDdWsp', clientId: '1j7r06083f2in6eftqolup0u7n', rekognitionBucket: 'rekognition-pics', albumName: 'usercontent', bucketRegion: 'us-east-1', ddbTableName: 'LoginTrail', cognito_idp_endpoint: '', cognito_identity_endpoint: '', sts_endpoint: '', dynamodb_endpoint: '', s3_endpoint: '' };

HTML1300: Navigation occurred. home DynamoDBService: constructor main.bundle.js (2022,9) AppComponent: constructor main.bundle.js (44,9) AppComponent: Checking if the user is already authenticated main.bundle.js (47,9) BEGIN getUserPool main.bundle.js (1579,9) END getUserPool main.bundle.js (1583,9) UserLoginService: can't retrieve the current user main.bundle.js (1243,13) AppComponent: the user is authenticated: false main.bundle.js (51,9) BEGIN getIdToken main.bundle.js (1651,9) BEGIN getUserPool main.bundle.js (1579,9) END getUserPool main.bundle.js (1583,9) AppComponent: calling initAwsService in callback main.bundle.js (58,17) BEGIN initAwsService main.bundle.js (950,9) AwsUtil: Running initAwsService() main.bundle.js (961,9) END initAwsService main.bundle.js (967,9) Angular is running in the development mode. Call enableProdMode() to enable the production mode. vendor.bundle.js (5470,9) HomeComponent constructor main.bundle.js (599,9) HomeLandingComponent constructor main.bundle.js (585,9) LoginComponent constructor login.component.ts (19,9) Checking if the user is already authenticated. If so, then redirect to the secure site login.component.ts (24,9) BEGIN getUserPool cognito.service.ts (49,9) END getUserPool cognito.service.ts (53,9) UserLoginService: can't retrieve the current user user-login.service.ts (145,13) BEGIN LoginComponent.isLoggedIn - isLoggedIn = false login.component.ts (56,9) Checking if the user is already authenticated. If so, then redirect to the secure site - after this.userService.isAuthenticated(this) login.component.ts (26,9) UserLoginService: starting the authentication user-login.service.ts (16,9) BEGIN getUserPool cognito.service.ts (49,9) END getUserPool cognito.service.ts (53,9) UserLoginService: authenticationData: {"Username":"steve@soaconsultingservices.com","Password":"testme123"} user-login.service.ts (29,9) UserLoginService: userData: {"Username":"steve@soaconsultingservices.com","Pool":{"userPoolId":"us-east-1_x3YEDdWsp","clientId":"1j7r06083f2in6eftqolup0u7n","client":{"config":{"credentials":null,"credentialProvider":null,"region":"us-east-1","logger":null,"apiVersions":{},"apiVersion":"2016-04-19","endpoint":"cognito-idp.us-east-1.amazonaws.com","httpOptions":{"timeout":120000},"maxRedirects":10,"paramValidation":true,"sslEnabled":true,"s3ForcePathStyle":false,"s3BucketEndpoint":false,"s3DisableBodySigning":true,"computeChecksums":true,"convertResponseTypes":true,"correctClockSkew":false,"customUserAgent":null,"dynamoDbCrc32":true,"systemClockOffset":0,"signatureVersion":"v4","signatureCache":true,"retryDelayOptions":{},"useAccelerateEndpoint":false},"isGlobalEndpoint":false,"endpoint":{"protocol":"https:","host":"cognito-idp.us-east-1.amazonaws.com","port":443,"hostname":"cognito-idp.us-east-1.amazonaws.com","pathname":"/","path":"/","href":"https://cognito-idp.us-east-1.amazonaws.com/"},"_clientId":4},"storage":{}}} user-login.service.ts (30,9) UserLoginService: Params set...Authenticating the user user-login.service.ts (32,9) UserLoginService: config is {"credentials":null,"credentialProvider":null,"region":"us-east-1","logger":null,"apiVersions":{},"apiVersion":null,"httpOptions":{"timeout":120000},"maxRedirects":10,"paramValidation":true,"sslEnabled":true,"s3ForcePathStyle":false,"s3BucketEndpoint":false,"s3DisableBodySigning":true,"computeChecksums":true,"convertResponseTypes":true,"correctClockSkew":false,"customUserAgent":null,"dynamoDbCrc32":true,"systemClockOffset":0,"signatureVersion":null,"signatureCache":true,"retryDelayOptions":{},"useAccelerateEndpoint":false} user-login.service.ts (34,9) In authenticateUser onSuccess callback user-login.service.ts (42,17) BEGIN buildCognitoCreds - idTokenJwteyJraWQiOiJ1MXZGMzlPN0FIS2VGS0ZncGYyMDNNQVFXUEN4UVZOYXYybjZtQVZHMTY4PSIsImFsZyI6IlJTMjU2In0.eyJzdWIiOiI4MWZlMTE3OC04YmNhLTQyMjYtYWMzNS1kMTI2ZjU0Mzg2MTgiLCJhdWQiOiIxajdyMDYwODNmMmluNmVmdHFvbHVwMHU3biIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJ0b2tlbl91c2UiOiJpZCIsImF1dGhfdGltZSI6MTUwNTY3MjYxMywiaXNzIjoiaHR0cHM6XC9cL2NvZ25pdG8taWRwLnVzLWVhc3QtMS5hbWF6b25hd3MuY29tXC91cy1lYXN0LTFfeDNZRURkV3NwIiwibmlja25hbWUiOiJzdGV2ZWIiLCJjb2duaXRvOnVzZXJuYW1lIjoiODFmZTExNzgtOGJjYS00MjI2LWFjMzUtZDEyNmY1NDM4NjE4IiwiZXhwIjoxNTA1Njc2MjEzLCJpYXQiOjE1MDU2NzI2MTMsImVtYWlsIjoic3RldmVAc29hY29uc3VsdGluZ3NlcnZpY2VzLmNvbSJ9.UVu4ix93Xs5tA-k64rpG29UsvmMYcHGPkGGzdVY8-94RTb5ViDAPuHFBrhPiNbTLiXtl-HYNUDxlew2XINQoK8FTCbMNyUqE3So3NFrHHoagzAa_PO-2UlD2058_lYIheHxp1tZLtCte_dajm0GCU7tXGjhoKNdsLGD5IcLj6CRGP_tLuwyUGRBzh-LY9MV8OhZyvGT8Y1BOGHf9NNYHYoY2d1ItOuyiEUUxNJFmtuoNvdVsLzKjX2qhYBqubz0KLqv78y6dqFtcIr1XmRVIxTOyLlgAK4QAH0qkhs5WLRKi6hmsvR1XxMx5cVK-dkUqveHta5H_TVVEjkEsEhXYdw cognito.service.ts (79,9) buildCognitoCreds -params = {"IdentityPoolId":"us-east-1:bc9425dc-ba77-4f39-9ada-0ce48fb122cb","Logins":{"cognito-idp.us-east-1.amazonaws.com/us-east-1_x3YEDdWsp":"eyJraWQiOiJ1MXZGMzlPN0FIS2VGS0ZncGYyMDNNQVFXUEN4UVZOYXYybjZtQVZHMTY4PSIsImFsZyI6IlJTMjU2In0.eyJzdWIiOiI4MWZlMTE3OC04YmNhLTQyMjYtYWMzNS1kMTI2ZjU0Mzg2MTgiLCJhdWQiOiIxajdyMDYwODNmMmluNmVmdHFvbHVwMHU3biIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJ0b2tlbl91c2UiOiJpZCIsImF1dGhfdGltZSI6MTUwNTY3MjYxMywiaXNzIjoiaHR0cHM6XC9cL2NvZ25pdG8taWRwLnVzLWVhc3QtMS5hbWF6b25hd3MuY29tXC91cy1lYXN0LTFfeDNZRURkV3NwIiwibmlja25hbWUiOiJzdGV2ZWIiLCJjb2duaXRvOnVzZXJuYW1lIjoiODFmZTExNzgtOGJjYS00MjI2LWFjMzUtZDEyNmY1NDM4NjE4IiwiZXhwIjoxNTA1Njc2MjEzLCJpYXQiOjE1MDU2NzI2MTMsImVtYWlsIjoic3RldmVAc29hY29uc3VsdGluZ3NlcnZpY2VzLmNvbSJ9.UVu4ix93Xs5tA-k64rpG29UsvmMYcHGPkGGzdVY8-94RTb5ViDAPuHFBrhPiNbTLiXtl-HYNUDxlew2XINQoK8FTCbMNyUqE3So3NFrHHoagzAa_PO-2UlD2058_lYIheHxp1tZLtCte_dajm0GCU7tXGjhoKNdsLGD5IcLj6CRGP_tLuwyUGRBzh-LY9MV8OhZyvGT8Y1BOGHf9NNYHYoY2d1ItOuyiEUUxNJFmtuoNvdVsLzKjX2qhYBqubz0KLqv78y6dqFtcIr1XmRVIxTOyLlgAK4QAH0qkhs5WLRKi6hmsvR1XxMx5cVK-dkUqveHta5H_TVVEjkEsEhXYdw"}} cognito.service.ts (96,9) buildCognitoCreds - serviceConfigs = {} cognito.service.ts (98,9) buildCognitoCreds - AWS.CognitoIdentityCredentials = {"expired":true,"expireTime":null,"params":{"IdentityPoolId":"us-east-1:bc9425dc-ba77-4f39-9ada-0ce48fb122cb","Logins":{"cognito-idp.us-east-1.amazonaws.com/us-east-1_x3YEDdWsp":"eyJraWQiOiJ1MXZGMzlPN0FIS2VGS0ZncGYyMDNNQVFXUEN4UVZOYXYybjZtQVZHMTY4PSIsImFsZyI6IlJTMjU2In0.eyJzdWIiOiI4MWZlMTE3OC04YmNhLTQyMjYtYWMzNS1kMTI2ZjU0Mzg2MTgiLCJhdWQiOiIxajdyMDYwODNmMmluNmVmdHFvbHVwMHU3biIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJ0b2tlbl91c2UiOiJpZCIsImF1dGhfdGltZSI6MTUwNTY3MjYxMywiaXNzIjoiaHR0cHM6XC9cL2NvZ25pdG8taWRwLnVzLWVhc3QtMS5hbWF6b25hd3MuY29tXC91cy1lYXN0LTFfeDNZRURkV3NwIiwibmlja25hbWUiOiJzdGV2ZWIiLCJjb2duaXRvOnVzZXJuYW1lIjoiODFmZTExNzgtOGJjYS00MjI2LWFjMzUtZDEyNmY1NDM4NjE4IiwiZXhwIjoxNTA1Njc2MjEzLCJpYXQiOjE1MDU2NzI2MTMsImVtYWlsIjoic3RldmVAc29hY29uc3VsdGluZ3NlcnZpY2VzLmNvbSJ9.UVu4ix93Xs5tA-k64rpG29UsvmMYcHGPkGGzdVY8-94RTb5ViDAPuHFBrhPiNbTLiXtl-HYNUDxlew2XINQoK8FTCbMNyUqE3So3NFrHHoagzAa_PO-2UlD2058_lYIheHxp1tZLtCte_dajm0GCU7tXGjhoKNdsLGD5IcLj6CRGP_tLuwyUGRBzh-LY9MV8OhZyvGT8Y1BOGHf9NNYHYoY2d1ItOuyiEUUxNJFmtuoNvdVsLzKjX2qhYBqubz0KLqv78y6dqFtcIr1XmRVIxTOyLlgAK4QAH0qkhs5WLRKi6hmsvR1XxMx5cVK-dkUqveHta5H_TVVEjkEsEhXYdw"}},"data":null,"_identityId":null,"_clientConfig":{}} cognito.service.ts (102,9) END buildCognitoCreds cognito.service.ts (104,9) In authenticateUser onSuccess callback - creds = {"expired":true,"expireTime":null,"params":{"IdentityPoolId":"us-east-1:bc9425dc-ba77-4f39-9ada-0ce48fb122cb","Logins":{"cognito-idp.us-east-1.amazonaws.com/us-east-1_x3YEDdWsp":"eyJraWQiOiJ1MXZGMzlPN0FIS2VGS0ZncGYyMDNNQVFXUEN4UVZOYXYybjZtQVZHMTY4PSIsImFsZyI6IlJTMjU2In0.eyJzdWIiOiI4MWZlMTE3OC04YmNhLTQyMjYtYWMzNS1kMTI2ZjU0Mzg2MTgiLCJhdWQiOiIxajdyMDYwODNmMmluNmVmdHFvbHVwMHU3biIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJ0b2tlbl91c2UiOiJpZCIsImF1dGhfdGltZSI6MTUwNTY3MjYxMywiaXNzIjoiaHR0cHM6XC9cL2NvZ25pdG8taWRwLnVzLWVhc3QtMS5hbWF6b25hd3MuY29tXC91cy1lYXN0LTFfeDNZRURkV3NwIiwibmlja25hbWUiOiJzdGV2ZWIiLCJjb2duaXRvOnVzZXJuYW1lIjoiODFmZTExNzgtOGJjYS00MjI2LWFjMzUtZDEyNmY1NDM4NjE4IiwiZXhwIjoxNTA1Njc2MjEzLCJpYXQiOjE1MDU2NzI2MTMsImVtYWlsIjoic3RldmVAc29hY29uc3VsdGluZ3NlcnZpY2VzLmNvbSJ9.UVu4ix93Xs5tA-k64rpG29UsvmMYcHGPkGGzdVY8-94RTb5ViDAPuHFBrhPiNbTLiXtl-HYNUDxlew2XINQoK8FTCbMNyUqE3So3NFrHHoagzAa_PO-2UlD2058_lYIheHxp1tZLtCte_dajm0GCU7tXGjhoKNdsLGD5IcLj6CRGP_tLuwyUGRBzh-LY9MV8OhZyvGT8Y1BOGHf9NNYHYoY2d1ItOuyiEUUxNJFmtuoNvdVsLzKjX2qhYBqubz0KLqv78y6dqFtcIr1XmRVIxTOyLlgAK4QAH0qkhs5WLRKi6hmsvR1XxMx5cVK-dkUqveHta5H_TVVEjkEsEhXYdw"}},"data":null,"_identityId":null,"_clientConfig":{}} user-login.service.ts (46,17) In authenticateUser onSuccess callback - clientParams = {} user-login.service.ts (62,17) UserLoginService: before new STS user-login.service.ts (63,17) UserLoginService: after new STS user-login.service.ts (65,17) UserLoginService: Successfully set the AWS credentials - err = CredentialsError: Missing credentials in config user-login.service.ts (67,21) UserLoginService: Successfully set the AWS credentials - data = null user-login.service.ts (68,21) UserLoginService: Successfully set the AWS credentials user-login.service.ts (69,21) BEGIN getUserPool cognito.service.ts (49,9) END getUserPool cognito.service.ts (53,9) UserLoginService: Session is true user-login.service.ts (140,21) SecureHomeComponent: constructor securehome.component.ts (15,9) BEGIN In MyProfileComponent constructor myprofile.component.ts (19,9) BEGIN getUserPool cognito.service.ts (49,9) END getUserPool cognito.service.ts (53,9) UserLoginService: Session is true user-login.service.ts (140,21) In MyProfileComponent BEGIN isLoggedIn myprofile.component.ts (25,9) In GetParametersCallback contructor BEGIN myprofile.component.ts (47,9) In GetParametersCallback contructor END myprofile.component.ts (48,9) BEGIN UserParametersService.getParameters user-parameters.service.ts (11,9) BEGIN getUserPool cognito.service.ts (49,9) END getUserPool cognito.service.ts (53,9) UserParametersService.getParameters = cognitoUser != null user-parameters.service.ts (15,13) In MyProfileComponent END isLoggedIn myprofile.component.ts (31,9) END In MyProfileComponent constructor myprofile.component.ts (21,9) HTTP400: BAD REQUEST - The request could not be processed by the server due to invalid syntax. (XHR)POST - https://cognito-identity.us-east-1.amazonaws.com/ HTTP400: BAD REQUEST - The request could not be processed by the server due to invalid syntax. (XHR)POST - https://cognito-identity.us-east-1.amazonaws.com/ In GetParametersCallback callbackWithParam BEGIN myprofile.component.ts (56,9) this.cognitoUtil.getCognitoIdentity(): undefined myprofile.component.ts (67,9) In GetParametersCallback callbackWithParam END myprofile.component.ts (69,9)

soacs commented 6 years ago

This was indeed an pool client app id issue!!!!!!!!!!!! I had checked this many times. But in the cognito identity config in console I was pointing to an incorrect app client id corresponding to user pool. unbelievable. With all the async callbacks it was hard to tell where when etc.

The good news is I debug out site my real site which is integrated with this angular quick start and I can go back and finish my app this week. Sorry for the long debug - this is my 3rd cognito implementation and was still time consuming even though this time I used your code for angular 4