Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hammadev opened this issue Mar 5, 2024 · 5 comments

Comments

@hammadev
Copy link

hammadev commented Mar 5, 2024

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
Copy link
Contributor

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
Copy link
Author

hammadev commented Mar 5, 2024

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
Copy link
Contributor

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
Copy link
Author

hammadev commented Mar 6, 2024

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
Copy link
Contributor

Could you get in touch with us at [email protected]? This was you can share more of your code and the keys being used so I can look to replicate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants