flutter
flutter

Reputation: 6766

The correct token to use with GraphQl?

I'm using the latest official aws plugin and the flutter graphql plugin. I want to use AppSync. And in the graphql readme it describes how to do this.

To use with an AppSync GraphQL API that is authorized with AWS Cognito User Pools, simply pass the JWT token for your Cognito user session in to the AuthLink:

// Where `session` is a CognitorUserSession
// from amazon_cognito_identity_dart_2
final token = session.getAccessToken().getJwtToken();

final AuthLink authLink = AuthLink(
  getToken: () => token,
);

My problem is from the aws plugin, There is a method called fetchAuthSession that returns a session with different tokens. But it doesn't return the jwtToken.. Are any of the returned tokens used for AppSync? Please click the session link for the different tokens...

Upvotes: 1

Views: 552

Answers (1)

flutter
flutter

Reputation: 6766

The token that you need for AppSync can be got by the Amplify plugin. It's called accessToken

Future<String> getAcessToken() async {
    CognitoAuthSession res = await Amplify.Auth.fetchAuthSession(options: CognitoSessionOptions(getAWSCredentials: true));
    final accessToken = res.userPoolTokens.accessToken;
    return accessToken;
  }

Upvotes: 1

Related Questions