如何设置从 Thruway 客户端到 Crossbar 路由器的 WAMP 身份验证?

How can I set up WAMP authentication from a Thruway client to a Crossbar router?

我正在兜圈子试图让它发挥作用...

情况如下:

我有一个 PHP 网络应用程序,它通过 Crossbar.io router using Thruway 对多个微服务进行远程过程调用 (RPC)。匿名呼叫工作正常,但现在我想添加身份验证。

这里是 Crossbar 配置:

{
  "controller": {
  },
  "workers": [
    {
      "type": "router",
      "realms": [
        {
          "name": "dashboard",
          "roles": [
            {
              "name": "microservice",
              "permissions": [
                {
                  "uri": "*",
                  "publish": true,
                  "subscribe": true,
                  "call": true,
                  "register": true
                }
              ]
            }
          ]
        }
      ],
      "transports": [
        {
          "type": "websocket",
          "endpoint": {
            "type": "tcp",
            "port": 80
          },
          "auth": {
            "wampcra": {
              "type": "static",
              "users": {
                "client1": {
                  "secret": "secret1",
                  "role": "microservice"
                }
              }
            }
          }
        }
      ]
    }
  ]
}

Crossbar 服务器(我希望)仅设置为路由器。所有 clients/workers 都在其他服务器上。我一直在关注 this example for the Crossbar config - specifically, this configuration file。示例和我的配置之间有几个重要的区别:示例服务器被配置为路由器并且还提供静态网页(我的没有)并且示例服务器包含一个 Python 组件(如果我没看错)不是 material 身份验证过程。

在我的开发环境中,我试图让身份验证为一个客户端工作。这是客户端代码:

<?php

// include the autoloader
//
require __DIR__ . '/vendor/autoload.php';

use Thruway\ClientSession;
use Thruway\Peer\Client;
use Thruway\Transport\PawlTransportProvider;
use Thruway\Authentication\ClientWampCraAuthenticator;

// create the WAMP client
//
$client = new Client('dashboard');


$auth = new ClientWampCraAuthenticator("client1", "secret1");
$client->addClientAuthenticator($auth);

// add the WAMP transport provider
//
$client->addTransportProvider(
    new PawlTransportProvider('ws://192.168.1.10/')
);

// handle the "open" (connect) event
//
$client->on('open', function (ClientSession $session) {

    // register the getImageData procedure
    //
    $session->register('service.client1.get', function ($data) {
        return (new Client)->get();
    });

});

// start the client
//
$client->start();

问题是服务器从未发送 "challenge" 消息。当客户端尝试连接时,我收到以下调试消息:

2015-07-07T13:58:17.7451860 debug      [Thruway\Transport\PawlTransportProvider 204] Received: [3,{"message":"no user with authid 'anonymous' in user database"},"wamp.error.not_authorized"]

任何人都可以解释我需要做什么额外的配置才能让服务器挑战客户端吗?

我找到了...

我一定是在今天看到的所有例子中都忽略了这一点。解决方法是在调用$client->addClientAuthenticator($auth);

之前添加$client->setAuthId('client1');