1
votes

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...

1
were you able to resolve this issue? I am also trying to figure out how to call AppSync!! - Ashootosh Bhardwaj
the token is called accessToken see below how to get it @AshootoshBhardwaj - flutter
thanks.. I was using native cognito Authentication page using Webview inside Flutter. The Access Token and ID Token were both part of authenticated URL. I used substring thereafter to parse Access Token and that did the trick.. Thanks anyways! - Ashootosh Bhardwaj

1 Answers

1
votes

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;
  }