-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathindex.php
54 lines (44 loc) · 1.52 KB
/
index.php
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
<?php
$respondWithJsonAndExit = function (array $responsePayload): void {
$responsePayloadString = json_encode($responsePayload);
echo $responsePayloadString;
file_put_contents('php://stdout', sprintf("Responding with: %s\n", $responsePayloadString));
exit;
};
// This is an example implementation of the REST auth Password Provider.
// Learn more here: https://github.com/ma1uta/matrix-synapse-rest-password-provider
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $_SERVER['REQUEST_URI'] === '/_matrix-internal/identity/v1/check_credentials') {
$bodyPayload = file_get_contents('php://input');
$payload = json_decode($bodyPayload, true, 3);
if ($payload === null) {
$respondWithJsonAndExit([
'auth' => [
'success' => false,
'message' => 'Invalid JSON payload',
],
]);
}
if (!array_key_exists('user', $payload) || !array_key_exists('id', $payload['user']) || !array_key_exists('password', $payload['user'])) {
$respondWithJsonAndExit([
'auth' => [
'success' => false,
'message' => 'Invalid payload (no user field or id/password subfields)',
],
]);
}
list($matrixId, $password) = [$payload['user']['id'], $payload['user']['password']];
// You need to validate `$matrixId` and `$password` here.
// For this example, we simply authenticate anyone with any password.
$respondWithJsonAndExit([
'auth' => [
'success' => true,
'mxid' => $matrixId,
]
]);
}
$respondWithJsonAndExit([
'auth' => [
'success' => false,
'message' => 'Bad call (incorrect route or HTTP request method)',
],
]);