I am trying to verify the confirmation code for users signing up for the application using AWS Cognito in Flutter. I am receiving a Bad request, Status 400 error NotAuthorizedException
(full error shown on the bottom). I set up a user pool and an app client using AWS Cognito through the AWS Dashboard. I am using the amazon_cognito_identity_dart_2
library in the Flutter application.
amazon_cognito_identity_dart_2: ^3.6.5
Below is the code. The confirmSignUp
method is where I am stuck. Please insert the user pool ID, client ID, and client secret if planning on running the code:
import 'package:amazon_cognito_identity_dart_2/cognito.dart';
import 'dart:convert';
class CognitoService {
final List<AttributeArg> userAttributes = [];
final CognitoUserPool userPool = new CognitoUserPool(
'UserPoolID', 'Client Id', clientSecret: 'Client Secret');
// Working
Future<bool> signUp(String email, String password) async {
try {
await userPool.signUp(email, password);
return true;
} catch (e) {
print(e);
return false;
}
}
// Below is causing the error
Future<bool> confirmSignUp(String email, String confirmationCode) async {
try {
final cognitoUser = CognitoUser(email, userPool);
return await cognitoUser.confirmRegistration(confirmationCode);
} catch (e) {
print(e);
return false;
}
}
}
The error states:
browser_client.dart:101
POST https://cognito-idp.us-east-1.amazonaws.com/ 400 (Bad Request)
Followed by:
CognitoClientException{statusCode: 400, code: NotAuthorizedException, name: NotAuthorizedException, message: Client 4je8c3ohh0nnqogebbc2e8c8mt is configured with secret but SECRET_HASH was not received}
I enter the confirmation number but the user is never authorized.
Any advice on the matter is appreciated.
2
Answers
I created a new user pool and it appears to work now. I did not enable the option to generate a client secret. Thank you for the help!
as explained in the comment section can you try and implment this :