aws / aws-appsync-community

The AWS AppSync community
https://aws.amazon.com/appsync
Apache License 2.0
506 stars 32 forks source link

GraphQL lambda authorizer not being called when a cognito acessToken is sent #312

Closed HidekiHiguchi closed 10 months ago

HidekiHiguchi commented 1 year ago

Hello, I ran into this issue while configuring a new GraphQL lambda authorizer on a new project, As you can see from the issue I had openned in amplify-flutter repository

https://github.com/aws-amplify/amplify-flutter/issues/3480

The lambda authorizer is not being called whenever I pass the cognito generated token, but any other string is getting through, is this the expected behavior?

HidekiHiguchi commented 1 year ago

The issue was solved with the following workaround:

class CustomFunctionProvider extends FunctionAuthProvider {
  const CustomFunctionProvider();
  @override
  Future<String?> getLatestAuthToken() async  {
    String? token = (await Amplify.Auth.fetchAuthSession() as CognitoAuthSession)
        .userPoolTokensResult.value.accessToken.toJson();
    return '{"accessToken": "$token"}';
  }
}