dongque4778 2018-08-01 22:02
浏览 67

Pusher / Chatkit:路径和访问令牌中的InstanceID不匹配

What?

I am currently building a react native app with chatkit, however the authentication seems to fail and keeps bringing back the following message: Instance ID in the path and the access token don't match

I'm using Laravel as a backend and have the following route: Route::post('/chatkit-auth-user', 'API\MessagesController@authenticateChatkitUser');

Within this method I authenticate the user depending on their user ID like so:

public function authenticateChatkitUser(Request $request)
{
    $userId = $request->input('user_id');
    $authData = $this->chatkit->authenticate([
        'user_id' => "{$userId}",
    ]);

    return response()
        ->json(
            $authData['body'],
            $authData['status']
        );
}

The token is generate which is then obviously passed into the TokenProvider instance like so:

const url = 'https://my-endpoint.com/api/chatkit-auth-user';
const userToken = this.state.user.authToken;
const tokenProvider = new Chatkit.TokenProvider({
  url,
  headers: {
    Authorization: 'Bearer ' + userToken,
    'Content-Type': 'application/json',
  },
});
const chatManager = new Chatkit.ChatManager({
  instanceLocator: '<MY_INSTANCE_LOCATOR_ID>',
  userId: `${this.state.user.userId}`,
  tokenProvider: tokenProvider
});

chatManager.connect().then(currentUser => {
  this.state.currentUser = currentUser;
  console.log(currentUser);
  this.currentUser.subscribeToRoom({
    roomId: CHATKIT_ROOM_ID,
    hooks: {
      onNewMessage: this.onReceive.bind(this)
    }
  });
});

currentUser never gets consoled and always returns a 403 with the message in the title. From the docs, I think I've implemented everything correctly, I have even span up a heroku app with https://github.com/pusher/chatkit-server-node, the same issue still occurs. I have spent a couple of days trying to figure this out and would appreciate if I could get some guidance if I'm doing anything wrong!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#hadoop#的问题,请各位专家解答!
    • ¥15 如何批量抓取网站信息
    • ¥15 Spring Boot离线人脸识别
    • ¥15 NRF24L01能发送但是不能接收
    • ¥15 想问一下这种情况怎么解决呢(关键词-file)
    • ¥15 python Flassk 模块部署 服务器时报错
    • ¥15 Opencv(C++)异常
    • ¥15 VScode上配置C语言环境
    • ¥15 汇编语言没有主程序吗?
    • ¥15 这个函数为什么会爆内存