-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathheader-auth.php
More file actions
72 lines (63 loc) · 1.8 KB
/
Copy pathheader-auth.php
File metadata and controls
72 lines (63 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/**
* This file is part of the Elephant.io package
*
* For the full copyright and license information, please view the LICENSE file
* that was distributed with this source code.
*
* @copyright ElephantIO
* @copyright Wisembly
* @license http://www.opensource.org/licenses/MIT-License MIT License
*/
require __DIR__ . '/common.php';
$namespace = 'header-auth';
$token = 'this_is_peter_token';
$event = 'message';
$logger = setup_logger();
// create first instance
$client = setup_client($namespace, $logger, [
'headers' => [
'X-My-Header' => 'websocket rocks',
'Authorization' => 'Bearer ' . $token,
'User' => 'peter',
]
]);
$data = [
'message' => 'How are you?',
'token' => $token,
];
echo sprintf("Sending message: %s\n", inspect($data));
$client->emit($event, $data);
if (is_object($retval = $client->wait($event))) {
echo sprintf("Got a reply: %s\n", $retval->inspect());
}
$client->disconnect();
// create second instance
$client = setup_client($namespace, $logger, [
'headers' => [
'X-My-Header' => 'websocket rocks',
'Authorization' => 'Bearer ' . $token,
'User' => 'peter',
]
]);
$data = [
'message' => 'Do you remember me?',
'token' => $token,
];
echo sprintf("Sending message: %s\n", inspect($data));
$client->emit($event, $data);
if (is_object($retval = $client->wait($event))) {
echo sprintf("Got a reply: %s\n", $retval->inspect());
}
// send message with invalid token
$invalidToken = 'this_is_invalid_peter_token';
$data = [
'message' => 'Do you remember me?',
'token' => $invalidToken,
];
echo sprintf("Sending message: %s\n", inspect($data));
$client->emit($event, $data);
if (is_object($retval = $client->wait($event))) {
echo sprintf("Got a reply: %s\n", $retval->inspect());
}
$client->disconnect();