awslabs / aws-mobile-appsync-sdk-js

JavaScript library files for Offline, Sync, Sigv4. includes support for React Native
Apache License 2.0
920 stars 266 forks source link

Subscription doesn't seem to work with OIDC authentication. #569

Open zhaoyi0113 opened 4 years ago

zhaoyi0113 commented 4 years ago

Note: If your issue/feature-request/question is regarding the AWS AppSync service, please log it in the official AWS AppSync forum

Do you want to request a feature or report a bug? Bug

What is the current behavior? No response when I sbuscribe a topic If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.

I have configured @aws_oidc on my schema in Appsync:

type Subscription {
    responseTransaction(id: ID!): Transaction!
        @aws_subscribe(mutations: ["responseTransaction"])
@aws_iam
@aws_cognito_user_pools
@aws_oidc
@aws_api_key
}

and I create a client app to subscribe the topic:

const createClient = (url: string) => {
  const client = new AWSAppSyncClient({
    url,
    region: 'ap-southeast-2',
    auth: {
      type: AUTH_TYPE.OPENID_CONNECT,
      jwtToken: () => 'Bearer xxxx'
    },
    disableOffline: true, //Uncomment for AWS Lambda
  });
  return client;
};

createClient(URL).hydrated()
    .then((gq) => {
         gqClient = gq;
      console.log('send subscription transaction response');
      const observable = gqClient.subscribe({
        query: requestTxn,
        fetchPolicy: 'network-only',
        variables: { id: '123' },
      });
      const realtimeResults = function realtimeResults(data: any) {
        console.log('realtime data: ', data);
      };

      observable.subscribe({
        next: realtimeResults,
        complete: () => {
          console.log('complete');
        },
        error: (err: Error) => console.error(err),
      });
  })..catch((err:Error) => {
      console.error(err);
    });

when I run the client, it is pending there and wait for published events. But it never gets an event even I published one. I have checked the subscription lambda resolver log and it is not triggered. It works fine if I change the authentication to @aws_api_key. It also works for mutation with @aws_oidc.

I also tried to type a wrong jwt token but it doesn't report any authentication error for me.

What is the expected behavior? It should give me an error message if authentication failed.

Which versions and which environment (browser, react-native, nodejs) / OS are affected by this issue? Did this work in previous versions? "aws-appsync": "^3.0.3"