blob: be7a7c5d1f4afa85d116a767a9de92e6cf24a553 (
plain)
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
|
<?php
use Digitigrade\HttpResponseStatus\Unauthorized;
use Digitigrade\Model\Instance;
use Digitigrade\Router;
Router::getInstance()->mount('/subscribe', function (array $args) {
$instance = Instance::findByRequestHeaders();
if ($instance == null) {
throw new Unauthorized();
}
$instance->auth->outboundPushEnabled = true;
$instance->save();
http_response_code(204); // "No Content"
// similar to in Instance->requestOutboundAuthToken, i'm gonna start auth in the other direction at this point
// my intention is that with these two pieces of code, any two digitigrade instances will complete full 2-way
// auth and subscribe "handshakes" when either one tries to auth with the other
// with a small network i don't think this will be a problem but as it grows this could cause a lot of extra
// overhead potentially?
// also worth noting this is run immediately rather than scheduled as a job. might be best to change that.
if ($instance->auth->outboundToken == null)
$instance->beginOutboundAuth();
elseif (!$instance->auth->inboundPushEnabled)
$instance->subscribe();
});
Router::getInstance()->mount('/unsubscribe', function (array $args) {
$instance = Instance::findByRequestHeaders();
if ($instance == null) {
throw new Unauthorized();
}
$instance->auth->outboundPushEnabled = false;
$instance->save();
http_response_code(204); // "No Content"
});
|