Skip to content

Commit 5d21315

Browse files
committed
testing auth
1 parent 1b46724 commit 5d21315

2 files changed

Lines changed: 18 additions & 44 deletions

File tree

auth.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,36 @@
66
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
77
header('Access-Control-Allow-Headers: Content-Type, Authorization');
88

9+
use \Firebase\JWT\JWT;
10+
11+
require 'vendor/autoload.php';
12+
913
if ($_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

3137
echo json_encode([
32-
'userId' => $userId,
33-
'room' => $roomId,
34-
'token' => $signature,
38+
'userId' => $userId,
39+
'room' => $roomId,
40+
'token' => $jwt,
3541
]);

test.php

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)