-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathtoken_pro.php
More file actions
76 lines (58 loc) · 1.54 KB
/
token_pro.php
File metadata and controls
76 lines (58 loc) · 1.54 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
<?php
include 'FirebaseJWT/JWT.php';
use \Firebase\JWT\JWT;
$apiKeySid = ''; //YOUR_API_KEY_SID
$apiKeySecret = ''; //YOUR_API_KEY_SECRET
$now = time();
$exp = $now + 100000000;
$userId = @$_GET['userId'];
$roomId = @$_GET['roomId'];
$rest = @$_GET['rest'];
$header = array('cty' => 'stringee-api;v=1');
if (!$apiKeySid || !$apiKeySecret) {
echo json_encode([
'err' => true,
'code' => 1
]);
exit;
}
if ($userId) {
$payload = array(
'jti' => $apiKeySid . '-' . $now,
'iss' => $apiKeySid,
'exp' => $exp,
'userId' => $userId
);
$clientAccessToken = JWT::encode($payload, $apiKeySecret, 'HS256', null, $header);
}
if ($rest) {
$payload = array(
'jti' => $apiKeySid . '-' . $now,
'iss' => $apiKeySid,
'exp' => $exp,
'rest_api' => true
);
$restAccessToken = JWT::encode($payload, $apiKeySecret, 'HS256', null, $header);
}
if ($roomId) {
$payload = array(
'jti' => $apiKeySid . '-' . $now,
'iss' => $apiKeySid,
'exp' => $exp,
'roomId' => $roomId,
'permissions' => array(
'publish' => true,
'subscribe' => true,
'control_room' => true,
'record' => false
)
);
$roomToken = JWT::encode($payload, $apiKeySecret, 'HS256', null, $header);
}
$res = array(
'access_token' => @$clientAccessToken,
'room_token' => @$roomToken,
'rest_access_token' => @$restAccessToken,
);
header('Access-Control-Allow-Origin: *');
echo json_encode($res);