我正绕着圈子想让这件事成功.
情况如下:
我有一个PHP应用程序,它通过Crossbar.io路由器使用特鲁威对几个微服务进行远程过程调用(RPC)。匿名呼叫运行良好,但现在我想添加身份验证。
下面是横梁配置:
{
"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组件,如果我正确地阅读了它,它对身份验证过程并不重要。
在我的开发环境中,我试图获得一个客户端的身份验证。以下是客户端代码:
<?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();问题是服务器从来不发送“质询”消息。当客户端尝试连接时,我收到以下调试消息:
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"]有人能解释一下我需要做什么额外的配置来让服务器挑战客户端吗?
发布于 2015-07-07 21:42:19
我找到了..。
在我今天看到的所有例子中,我一定忽略了这一点。解决方案是在调用$client->setAuthId('client1');之前添加$client->addClientAuthenticator($auth);
https://stackoverflow.com/questions/31279197
复制相似问题