首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何设置从Thruway客户端到交叉路由器的WAMP身份验证?

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

Stack Overflow用户
提问于 2015-07-07 21:02:31
回答 1查看 1.5K关注 0票数 2

我正绕着圈子想让这件事成功.

情况如下:

我有一个PHP应用程序,它通过Crossbar.io路由器使用特鲁威对几个微服务进行远程过程调用(RPC)。匿名呼叫运行良好,但现在我想添加身份验证。

下面是横梁配置:

代码语言:javascript
复制
{
  "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"
                }
              }
            }
          }
        }
      ]
    }
  ]
}

交叉服务器(我希望)只设置为路由器。所有客户/工作人员都在其他服务器上。我一直在跟踪这个例子的横栏配置-特别是此配置文件。在示例和my config之间有几个重要的区别:示例服务器被配置为一个路由器,并且还提供静态网页(我没有),示例服务器包括一个Python组件,如果我正确地阅读了它,它对身份验证过程并不重要。

在我的开发环境中,我试图获得一个客户端的身份验证。以下是客户端代码:

代码语言:javascript
复制
<?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();

问题是服务器从来不发送“质询”消息。当客户端尝试连接时,我收到以下调试消息:

代码语言:javascript
复制
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"]

有人能解释一下我需要做什么额外的配置来让服务器挑战客户端吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-07-07 21:42:19

我找到了..。

在我今天看到的所有例子中,我一定忽略了这一点。解决方案是在调用$client->setAuthId('client1');之前添加$client->addClientAuthenticator($auth);

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31279197

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档