oncesk / yii-node-socket

66 stars 46 forks source link

No Cookie Transmitted for /client #66

Closed hnq90 closed 9 years ago

hnq90 commented 9 years ago

Hello @oncesk I'm using your library with yii2 advanced template. Each time I connect to socket server, I got this handshake error NO COOKIE TRANSMITTED for /client

I have to use these configurations to got socker server running (yii node-socket/start).

I'm using frontend.dev for my virtualhost domain.

In console/config/main.php

<?php
$params = array_merge(
    require(__DIR__ . '/../../common/config/params.php'),
    require(__DIR__ . '/../../common/config/params-local.php'),
    require(__DIR__ . '/params.php'),
    require(__DIR__ . '/params-local.php')
);

return [
    'id' => 'app-console',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'controllerNamespace' => 'console\controllers',
    'controllerMap' => [
        'node-socket' => '\YiiNodeSocket\NodeSocketCommand',
    ],
    'components' => [
        'nodeSocket' => [
          'class' => '\YiiNodeSocket\NodeSocket',
          'host' => 'frontend.dev',
          'allowedServerAddresses' => [
              "localhost",
              "127.0.0.1",
              "frontend.dev"
          ],
          'origin' => '*:*',
          'sessionVarName' => 'PHPSESSID',
          'port' => 3001,
          'socketLogFile' => '/var/log/node-socket.log',
        ],
        'log' => [
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
    ],
    'params' => $params,
];

In frontend/config/main.php

<?php
$params = array_merge(
    require(__DIR__ . '/../../common/config/params.php'),
    require(__DIR__ . '/../../common/config/params-local.php'),
    require(__DIR__ . '/params.php'),
    require(__DIR__ . '/params-local.php')
);

return [
    'id' => 'app-frontend',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log', 'nodeSocket'],
    'controllerNamespace' => 'frontend\controllers',
    'components' => [
        'user' => [
            'identityClass' => 'common\models\User',
            'enableAutoLogin' => true,
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'nodeSocket' => [
            'class' => '\YiiNodeSocket\NodeSocket',
            'host' => 'frontend.dev',
            'allowedServerAddresses' => [
                "localhost",
                "127.0.0.1",
                "frontend.dev"
            ],
            'origin' => '*:*',
            'sessionVarName' => 'PHPSESSID',
            'port' => 3001,
            'socketLogFile' => '/var/log/node-socket.log',
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
    ],
    'params' => $params,
];

In common/config/main.php:

<?php
return [
    'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
    'aliases' => [
        '@YiiNodeSocket' => '@vendor/oncesk/yii-node-socket/lib/php',
        '@nodeWeb' => '@vendor/oncesk/yii-node-socket/lib/js'
    ],
    'components' => [
        'cache' => [
            'class' => 'yii\caching\FileCache',
            'cachePath' => '@common/runtime/cache'
        ],
    ],
    'language' => 'ja',  // or use ContentNegotiator with Accept-Language HTTP header
];

I tried to log the handshakeData but there's no cookie attribute and host become '0.0.0.0:3001'.

io.of('/client').authorization(function (handshakeData,accept) {
  console.log(handshakeData);
    if (!handshakeData.headers.cookie) {
        return accept('NO COOKIE TRANSMITTED', false);
    }
...
{ 
headers: 
   { host: '0.0.0.0:3001',
     connection: 'keep-alive',
     'cache-control': 'max-age=0',
     origin: 'http://frontend.dev',
     'x-firephp-version': '0.0.6',
     'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36',
     accept: '*/*',
     dnt: '1',
     referer: 'http://frontend.dev/index.php?r=site%2Fabout',
     'accept-encoding': 'gzip, deflate, sdch',
     'accept-language': 'en-US,en;q=0.8' },
  address: { address: '127.0.0.1', port: 54573 },
  time: 'Tue Nov 03 2015 16:27:17 GMT+0700 (ICT)',
  query: { t: '1446542837636' },
  url: '/socket.io/1/?t=1446542837636',
  xdomain: true,
  secure: undefined 
}

Thank you in advance.

oncesk commented 9 years ago

hi, you must have the same domains or ip adressess, example

your site works on frontend.dev - 127.0.0.1 you must run nodejs server on frontend.dev:3001

and connect to it using frontend.dev:3001

you are have an insecure connection, browser can not send cookie to another domain

seems like problem here

oncesk commented 9 years ago

do not forget clear assets

hnq90 commented 9 years ago

@oncesk Thanks for your response.

How can I know my nodejs server is running on frontend.dev:3001?

When I go to frontend.dev:3001, I got "Cannot GET /" message.

oncesk commented 9 years ago

can you show me you nodejs logs? nodejs server ran with you component configuration in console config

hnq90 commented 9 years ago

@oncesk Yes, of course. Please check it.

tail -f /var/log/node-socket.log
info: socket.io started
Listening frontend.dev:3001
Set origin:  *:*
debug: client authorized
info: handshake authorized 1clP_1qv2McfKY8CmEuT
debug: setting request GET /socket.io/1/websocket/1clP_1qv2McfKY8CmEuT
debug: set heartbeat interval for client 1clP_1qv2McfKY8CmEuT
debug: client authorized for 
debug: websocket writing 1::
debug: client unauthorized for /client
warn: handshake error NO COOKIE TRANSMITTED for /client
debug: websocket writing 7::/client:undefined
debug: emitting heartbeat for client 1clP_1qv2McfKY8CmEuT
debug: websocket writing 2::
debug: set heartbeat timeout for client 1clP_1qv2McfKY8CmEuT
debug: got heartbeat packet
debug: cleared heartbeat timeout for client 1clP_1qv2McfKY8CmEuT
debug: set heartbeat interval for client 1clP_1qv2McfKY8CmEuT
debug: emitting heartbeat for client 1clP_1qv2McfKY8CmEuT
debug: websocket writing 2::
debug: set heartbeat timeout for client 1clP_1qv2McfKY8CmEuT
debug: got heartbeat packet
debug: cleared heartbeat timeout for client 1clP_1qv2McfKY8CmEuT
debug: set heartbeat interval for client 1clP_1qv2McfKY8CmEuT
debug: emitting heartbeat for client 1clP_1qv2McfKY8CmEuT
debug: websocket writing 2::
debug: set heartbeat timeout for client 1clP_1qv2McfKY8CmEuT
debug: got heartbeat packet
debug: cleared heartbeat timeout for client 1clP_1qv2McfKY8CmEuT
debug: set heartbeat interval for client 1clP_1qv2McfKY8CmEuT
info: transport end (undefined)
debug: set close timeout for client 1clP_1qv2McfKY8CmEuT
debug: cleared close timeout for client 1clP_1qv2McfKY8CmEuT
debug: cleared heartbeat interval for client 1clP_1qv2McfKY8CmEuT
debug: discarding transport
tail: /var/log/node-socket.log: file truncated
info: socket.io started
{ host: 'frontend.dev',
  port: 3001,
  origin: ' *:*',
  allowedServers: { '0': '127.0.0.1', '1': 'localhost', '3': 'frontend.dev' },
  dbOptions: { driver: 'dummy', config: [] },
  checkClientOrigin: 1,
  sessionVarName: 'PHPSESSID',
  socketLogFile: '/var/log/node-socket.log' }
Listening frontend.dev:3001
Set origin:  *:*
oncesk commented 9 years ago

ok, what do you see in your browser console?

oncesk is my skype you can write me

hnq90 commented 9 years ago

@oncesk Oh, thank you. There're some people which have Skype account similiar to oncesk. Are you Aliaksei Panasik?

My Skype account is naruto_thf90.

Thanks.

oncesk commented 9 years ago

Yes

Отправлено с моего Xiaomi

Сообщение от "Huy Nguyen Quang notifications@github.com":

@oncesk Oh, thank you. There're some people which have Skype account similiar with oncesk. Are you Aliaksei Panasik?

My Skype account is naruto_thf90.

Thanks.

— Reply to this email directly or view it on GitHub.

tolik505 commented 9 years ago

Hi! Did you solve this issue? I have such problem too.

oncesk commented 9 years ago

Hi, yes @hnq90 solved this problem, show your configuration

tolik505 commented 9 years ago

I use yii1 version. 'nodeSocket' => array( 'class' => '\NodeSocket', 'host' => 'hoo.com.ua', // default is 127.0.0.1, can be ip or domain name, without http 'port' => 8081, // default is 3001, should be integer 'allowedServerAddresses' => array('46.101.160.165') ),

oncesk commented 9 years ago

On which domain working your website? Show your nodejs logs

Сообщение от "tolik505 notifications@github.com":

I use yii1 version. 'nodeSocket' => array( 'class' => '\NodeSocket', 'host' => 'hoo.com.ua', // default is 127.0.0.1, can be ip or domain name, without http 'port' => 8081, // default is 3001, should be integer 'allowedServerAddresses' => array('46.101.160.165') ),

— Reply to this email directly or view it on GitHub.

tolik505 commented 9 years ago

Sure info: socket.io started Listening hoo.com.ua:8081 Set origin: hoo.com.ua:* debug: client authorized info: handshake authorized zQSkeXEDmb1i4p-t5eF debug: setting request GET /socket.io/1/websocket/zQSkeXEDmb1i4p-t5eF debug: set heartbeat interval for client zQSkeXEDmb1i4p-t5eF debug: client authorized for debug: websocket writing 1:: debug: client unauthorized for /client warn: handshake error NO COOKIE TRANSMITTED for /client debug: websocket writing 7::/client:undefined debug: client authorized info: handshake authorized cYF7tdWcRbVLQMzd5eGA debug: setting request GET /socket.io/1/websocket/cYF7tdWcRbVLQMzd5eGA debug: set heartbeat interval for client cYF7tdWcRbVLQMzd5eGA debug: client authorized for debug: websocket writing 1:: debug: client unauthorized for /client warn: handshake error NO COOKIE TRANSMITTED for /client debug: websocket writing 7::/client:undefined info: transport end (undefined) debug: set close timeout for client zQSkeXEDmb1i4p-t5eF debug: cleared close timeout for client zQSkeXEDmb1i4p-t5eF debug: cleared heartbeat interval for client zQSkeXEDmb1i4p-t5eF debug: discarding transport debug: served static content /socket.io.js debug: client authorized info: handshake authorized GFlN2eE0eXWlMcHh5eGB debug: setting request GET /socket.io/1/websocket/GFlN2eE0eXWlMcHh5eGB debug: set heartbeat interval for client GFlN2eE0eXWlMcHh5eGB debug: client authorized for debug: websocket writing 1:: debug: client unauthorized for /client warn: handshake error NO COOKIE TRANSMITTED for /client debug: websocket writing 7::/client:undefined

oncesk commented 9 years ago

Your wensite domain should be hoo.com.ua

Отправлено с моего Xiaomi

Сообщение от "tolik505 notifications@github.com":

Sure info: socket.io started Listening hoo.com.ua:8081 Set origin: hoo.com.ua:* debug: client authorized info: handshake authorized zQSkeXEDmb1i4p-t5eF debug: setting request GET /socket.io/1/websocket/zQSkeXEDmb1i4p-t5eF debug: set heartbeat interval for client zQSkeXEDmb1i4p-t5eF debug: client authorized for debug: websocket writing 1:: debug: client unauthorized for /client warn: handshake error NO COOKIE TRANSMITTED for /client debug: websocket writing 7::/client:undefined debug: client authorized info: handshake authorized cYF7tdWcRbVLQMzd5eGA debug: setting request GET /socket.io/1/websocket/cYF7tdWcRbVLQMzd5eGA debug: set heartbeat interval for client cYF7tdWcRbVLQMzd5eGA debug: client authorized for debug: websocket writing 1:: debug: client unauthorized for /client warn: handshake error NO COOKIE TRANSMITTED for /client debug: websocket writing 7::/client:undefined info: transport end (undefined) debug: set close timeout for client zQSkeXEDmb1i4p-t5eF debug: cleared close timeout for client zQSkeXEDmb1i4p-t5eF debug: cleared heartbeat interval for client zQSkeXEDmb1i4p-t5eF debug: discarding transport debug: served static content /socket.io.js debug: client authorized info: handshake authorized GFlN2eE0eXWlMcHh5eGB debug: setting request GET /socket.io/1/websocket/GFlN2eE0eXWlMcHh5eGB debug: set heartbeat interval for client GFlN2eE0eXWlMcHh5eGB debug: client authorized for debug: websocket writing 1:: debug: client unauthorized for /client warn: handshake error NO COOKIE TRANSMITTED for /client debug: websocket writing 7::/client:undefined

— Reply to this email directly or view it on GitHub.

tolik505 commented 9 years ago

It is. But NO COOKIE TRANSMITTED

oncesk commented 9 years ago

You can check it in chrome dev tool when send first get request(handshake), check which headers sent, you can print headers in server.js

If you have the same domains cookies should be sent

Отправлено с моего Xiaomi

Сообщение от "tolik505 notifications@github.com":

It is. But NO COOKIE TRANSMITTED

— Reply to this email directly or view it on GitHub.

tolik505 commented 9 years ago

You are right, the host is different { headers: { host: 'hoo.dev.vintagedev.com.ua:8081', connection: 'keep-alive', 'cache-control': 'max-age=0', origin: 'http://hoo.com.ua', 'user-agent': 'Mozilla/5.0 (X11; Linux x8664) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36', accept: '/_', referer: 'http://hoo.com.ua/', 'accept-encoding': 'gzip, deflate, sdch', 'accept-language': 'ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4,uk;q=0.2' }, time: 'Tue Nov 24 2015 15:01:19 GMT-0500 (EST)', query: { t: '1448395278330' }, url: '/socket.io/1/?t=1448395278330', xdomain: true, secure: undefined } How have I set the configuration to fix this problem?

oncesk commented 9 years ago

You can try to proxying requests from

hoo.dev.vintagedev.com.ua server to hoo.com.ua, use nginx or iptables......


Use the same domain

you can try to set document.domain to the same domain level, but i think this will not work because you domain zone is com.ua and domain name is different

....

Сообщение от "tolik505 notifications@github.com":

You are right, the host is different { headers: { host: 'hoo.dev.vintagedev.com.ua:8081', connection: 'keep-alive', 'cache-control': 'max-age=0', origin: 'http://hoo.com.ua', 'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36', accept: '/', referer: 'http://hoo.com.ua/', 'accept-encoding': 'gzip, deflate, sdch', 'accept-language': 'ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4,uk;q=0.2' }, time: 'Tue Nov 24 2015 15:01:19 GMT-0500 (EST)', query: { t: '1448395278330' }, url: '/socket.io/1/?t=1448395278330', xdomain: true, secure: undefined } How have I set the configuration to fix this problem?

— Reply to this email directly or view it on GitHub.

oncesk commented 9 years ago

you can set the same domains

tolik505 commented 9 years ago

I'm not strong in nginx configuration. You say, I must change hostname 'hoo.dev.vintagedev.com.ua' to 'hoo.com.ua'. Is it right?

hnq90 commented 9 years ago

@tolik505 yes, you should do it.

oncesk commented 9 years ago

yes, and all will works, or you can use the same top level domain like

hoo.com.ua

then if you will create subdomains and you need nodesocket you need to set in javascript document.domain = 'hoo.com.ua';

example, for domain dev.hoo.com.ua and cookie will send

2015-11-25 11:50 GMT+03:00 tolik505 notifications@github.com:

I'm not strong in nginx configuration. You say, I must change hostname ' hoo.dev.vintagedev.com.ua' to 'hoo.com.ua'. Is it right?

— Reply to this email directly or view it on GitHub https://github.com/oncesk/yii-node-socket/issues/66#issuecomment-159537209 .

tolik505 commented 9 years ago

I've changed hostname, but log show the same host: 'hoo.dev.vintagedev.com.ua:8081'. http://joxi.ru/gmv70o9ixyZD02, http://joxi.ru/5mdQO83uv46gQ2. Perhaps, I've made something wrong.

oncesk commented 9 years ago

so, as i can see you have one server and several domains, in this case you can start your nodejs server on hoo.dev.vintagedev.com

change yii configuration, restart server, and check

tolik505 commented 9 years ago

With that config 'nodeSocket' => array( 'class' => '\NodeSocket', 'host' => 'hoo.dev.vintagedev.com', 'port' => 8081,
'allowedServerAddresses' => array('46.101.160.165') ),

info: socket.io started Listening 46.101.160.165:8081 Set origin: hoo.dev.vintagedev.com:* warn: illegal origin: http://hoo.com.ua

With that config 'nodeSocket' => array( 'class' => '\NodeSocket', 'host' => '46.101.160.165', 'port' => 8081,
'allowedServerAddresses' => array('46.101.160.165') ), info: socket.io started Listening 46.101.160.165:8081 Set origin: 46.101.160.165:* debug: served static content /socket.io.js warn: illegal origin: http://hoo.com.ua

oncesk commented 9 years ago

so, can you describe you app structure

oncesk commented 9 years ago

you can set origin in your yii configuration

'origin' => '*:*'
oncesk commented 9 years ago

and seems like you forget clean assets after changed yii configuration

tolik505 commented 9 years ago

Yes, you're right! I forgot to clean assets. But now, when I send message, there is such error Exception

Failed to connect to hoo.com.ua port 8081: Connection refused (/var/www/hoo/vendor/oncesk/yii-node-socket/lib/vendor/elephant.io/lib/ElephantIO/Client.php:372)

0 /var/www/hoo/vendor/oncesk/yii-node-socket/lib/vendor/elephant.io/lib/ElephantIO/Client.php(66): ElephantIO\Client->handshake()

1 /var/www/hoo/vendor/oncesk/yii-node-socket/lib/php/frames/AFrame.php(167): ElephantIO\Client->init()

2 /var/www/hoo/vendor/oncesk/yii-node-socket/lib/php/frames/AFrame.php(76): YiiNodeSocket\Frames\AFrame->emit()

3 /var/www/hoo/frontend/modules/user/controllers/PmController.php(134): YiiNodeSocket\Frames\AFrame->send()

4 [internal function]: user\controllers\PmController->actionView('32', '31')

oncesk commented 9 years ago

Seems like you forgit change yii configuration for web app, main.php config file

Отправлено с моего Xiaomi

Сообщение от "tolik505 notifications@github.com":

Yes, you're right! I forgot to clean assets. But now, when I send message, there is such error Exception

Failed to connect to hoo.com.ua port 8081: Connection refused (/var/www/hoo/vendor/oncesk/yii-node-socket/lib/vendor/elephant.io/lib/ElephantIO/Client.php:372)

0 /var/www/hoo/vendor/oncesk/yii-node-socket/lib/vendor/elephant.io/lib/ElephantIO/Client.php(66): ElephantIO\Client->handshake()

1 /var/www/hoo/vendor/oncesk/yii-node-socket/lib/php/frames/AFrame.php(167): ElephantIO\Client->init()

2 /var/www/hoo/vendor/oncesk/yii-node-socket/lib/php/frames/AFrame.php(76): YiiNodeSocket\Frames\AFrame->emit()

3 /var/www/hoo/frontend/modules/user/controllers/PmController.php(134): YiiNodeSocket\Frames\AFrame->send()

4 [internal function]: user\controllers\PmController->actionView('32', '31')

— Reply to this email directly or view it on GitHub.

tolik505 commented 9 years ago

Configurations in console/config/main.php and in frontend/config/main.php are identical. 'nodeSocket' => array( 'class' => '\NodeSocket', 'host' => 'hoo.com.ua', 'port' => 8081, 'allowedServerAddresses' => array('46.101.160.165'), ),

oncesk commented 9 years ago

did you remove 127.0.0.1 hoo.com.ua from /etc/hosts?

your website on domain hoo.com.ua and nodejs too, is it correct?

tolik505 commented 9 years ago

did you remove 127.0.0.1 hoo.com.ua from /etc/hosts? no, I didn't. Have I remove this row? your website on domain hoo.com.ua and nodejs to, is it correct? Yes, it is. { headers: { host: 'hoo.com.ua:8081', connection: 'keep-alive', 'user-agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36', origin: 'http://hoo.com.ua',

Events which are emitted in js, work perfectly, but events are emitted in action lead to the error.

oncesk commented 9 years ago

remove, and try to check

tolik505 commented 9 years ago

Yes, it works! Thanks a lot! You really helped me! You're a great man!

oncesk commented 9 years ago

excellent, do not at all)

dorw123 commented 7 years ago

Hello... I have the same issue...warn: handshake error NO COOKIE TRANSMITTED for /client How can I solve it?

oncesk commented 7 years ago

Hello,

This message can be mostly in two cases:

24 янв. 2017 г. 18:40 пользователь "Doru Popescu" notifications@github.com написал:

Hello... I have the same issue...warn: handshake error NO COOKIE TRANSMITTED for /client How can I solve it?

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/oncesk/yii-node-socket/issues/66#issuecomment-274839934, or mute the thread https://github.com/notifications/unsubscribe-auth/AB84jO3iK1uNL4Xill5qnNt8P_H-d0yNks5rVhtdgaJpZM4GawoH .