pusher / pusher-websocket-react-native

React Native official Pusher SDK
MIT License
61 stars 52 forks source link

Got Error: 'Invalid signature: Expected HMAC SHA256 hex digest' on authenticating user for private channel #149

Open hammadev opened 6 months ago

hammadev commented 6 months ago

The error i got on pusher debug console

Screenshot 2024-03-05 at 5 57 12 PM

here's my code

async function iniPusher() {
    const pusher = Pusher.getInstance();

    await pusher.init({
      apiKey: '',
      cluster: 'ap2',
      authEndpoint: `https://domain.com/api/v1/pusher/user-auth/${auth.user.id}`,
    });

    await pusher.connect();
    await pusher.subscribe({
      channelName: 'private-chat.' + auth.user.id,
      onEvent: event => {
        console.log(`Event received: ${event}`);
        const formattedData = formatEventData(event);
        setMessages(previousMessages =>
          GiftedChat.append(previousMessages, formattedData),
        );
      },
      onConnectionStateChange(currentState) {
        console.log(`Connection: ${currentState}`);
      },
      onError(message, code, e) {
        console.log(`onError: ${message} code: ${code} exception: ${e}`);
      },
      onSubscriptionSucceeded(channelName, data) {
        console.log(`onSubscriptionSucceeded: ${channelName} data: ${data}`);
      },
      onSubscriptionError(channelName, message, e) {
        console.log(
          `onSubscriptionError: ${message} channelName: ${channelName} Exception: ${e}`,
        );
      },
      onAuthorizer(channelName, socketId) {
        console.log(
          `calling onAuthorizer. channelName=${channelName}, socketId=${socketId},`,
        );

    });
  }

response I got from server

{
    "auth": "d980932ee394770d0950:50b4795375582e8dceb2a6597b8eab6f2f72c23e25b1ee9aa5fc9de9f2160e3f",
    "user_data": "{\"id\":61}"
}
benw-pusher commented 6 months ago

Do you receive this every time you attempt to subscribe? This is the result of an incorrect token specified either in the client or server - https://docs.bird.com/pusher/channels/channels/troubleshooting/why-am-i-receiving-the-invalid-signature-expected-hmac-sha256-error

hammadev commented 6 months ago

Do you receive this every time you attempt to subscribe? This is the result of an incorrect token specified either in the client or server - https://docs.bird.com/pusher/channels/channels/troubleshooting/why-am-i-receiving-the-invalid-signature-expected-hmac-sha256-error

yes, I receive this error every time, but the server correctly generates an auth token and on the client side, I haven't identified any errors.

benw-pusher commented 6 months ago

It might generate a token, but the token appears to be using incorrect values. You should ensure the key provided to the client is correct, along with the app id, key and secret provided to the generating server is valid.

hammadev commented 6 months ago

It might generate a token, but the token appears to be using incorrect values. You should ensure the key provided to the client is correct, along with the app id, key and secret provided to the generating server is valid.

Yes, I checked all values are the same and valid, even though it works fine in public channels.

benw-pusher commented 6 months ago

Could you get in touch with us at support@pusher.com? This was you can share more of your code and the keys being used so I can look to replicate