I am new to Flutter and AWS and I made a small project with facebook authentication. using:
- amazon_cognito_identity_dart: ^0.0.22
- flutter_facebook_login: ^3.0.0
On AWS I:
- Configured an API with a POST method
- Created a new Cognito User Pool
- Created a new App Client in the new Cognito User Pool
- Created a new Cognito Identity Pool with Facebook AppID from Facebook
I have a sign in function
signInFacebook() async {
final facebookLoginResult = await signInWithFacebook();
final credentials = new Credentials(
cognitoIdentityPoolId,
cognitoUserPoolId,
cognitoClientId,
facebookLoginResult.accessToken.token
);
a method signInWithFacebook:
import 'package:flutter_facebook_login/flutter_facebook_login.dart';
Future<FacebookLoginResult> signInWithFacebook() async {
final facebookLogin = FacebookLogin();
final facebookLoginResult = await facebookLogin.logIn(['email']);
return facebookLoginResult;
}
a class Credentials:
import 'package:amazon_cognito_identity_dart/cognito.dart';
class Credentials {
final CognitoCredentials _cognitoCredentials;
final String _token;
Credentials(String identityPoolId, String userPoolId, String clientId, this._token)
: _cognitoCredentials = new CognitoCredentials(identityPoolId, new CognitoUserPool(userPoolId, clientId));
Future<CognitoCredentials> get cognitoCredentials async {
await _cognitoCredentials.getAwsCredentials(_token);
return _cognitoCredentials;
}
}
and a credentials.dart with the Cognito credentials and the endpoint of the API
The problem is when it executes the method:
await _cognitoCredentials.getAwsCredentials(_token);
I get the following error:
CognitoClientException{statusCode: 400, code: NotAuthorizedException, name: NotAuthorizedException, message: Invalid login token. Not a valid OpenId Connect identity token.}
Why is the token I receive from facebook not valid? Am I missing something?
i solved updating to the
and using the method