File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66header ('Access-Control-Allow-Methods: POST, GET, OPTIONS ' );
77header ('Access-Control-Allow-Headers: Content-Type, Authorization ' );
88
9+ use \Firebase \JWT \JWT ;
10+
11+ require 'vendor/autoload.php ' ;
12+
913if ($ _SERVER ['REQUEST_METHOD ' ] === 'OPTIONS ' ) {
10- http_response_code (200 );
11- exit ;
14+ http_response_code (200 );
15+ exit ;
1216}
1317
18+ // For testing purposes, comment out user_id session check
1419// if (!isset($_SESSION['user_id'])) {
15- // http_response_code(403);
16- // echo json_encode(['error' => 'Unauthorized']);
17- // exit;
20+ // http_response_code(403);
21+ // echo json_encode(['error' => 'Unauthorized']);
22+ // exit;
1823// }
1924
2025$ secretApiKey = 'sk_dev_4oLJSBeKQJF8n3tCiEnqkC8f9mMM2gBhlIMIVZImq98FqiTNa_-SIsps6EMaQuG0 ' ;
21- $ userId = $ _GET ['user_id ' ];
26+ $ userId = $ _GET ['user_id ' ] ?? ' test_user ' ;
2227$ roomId = $ _POST ['room_id ' ] ?? 'my-room ' ;
2328
2429$ payload = [
25- 'userId ' => $ userId ,
26- 'room ' => $ roomId ,
30+ 'userId ' => $ userId ,
31+ 'room ' => $ roomId ,
32+ 'exp ' => time () + 3600 ,
2733];
2834
29- $ signature = hash_hmac ( ' sha256 ' , json_encode (value: $ payload) , $ secretApiKey );
35+ $ jwt = JWT :: encode ( $ payload , $ secretApiKey, ' HS256 ' );
3036
3137echo json_encode ([
32- 'userId ' => $ userId ,
33- 'room ' => $ roomId ,
34- 'token ' => $ signature ,
38+ 'userId ' => $ userId ,
39+ 'room ' => $ roomId ,
40+ 'token ' => $ jwt ,
3541]);
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments