Added CORS stuff for /v1/me.

This commit is contained in:
Pachira 2024-11-14 01:53:35 +00:00
parent 5cca82df07
commit 2896148124
2 changed files with 6 additions and 1 deletions

View file

@ -16,6 +16,7 @@ class V1Routes implements RouteHandler {
$router->get('/', fn() => ['status' => 'operational']);
$usersRoutes = new V1UsersRoutes($this->ctx, $this->ctx->getRpcClient()->scopeTo('misuzu:users:'));
$router->options('/me', $usersRoutes->getMe(...));
$router->get('/me', $usersRoutes->getMe(...));
$router->scopeTo('/users')->register($usersRoutes);
}

View file

@ -12,7 +12,11 @@ class V1UsersRoutes implements RouteHandler {
private RpcClient $rpc
) {}
public function getMe() {
public function getMe($response) {
$response->setHeader('Access-Control-Allow-Origin', '*');
$response->setHeader('Access-Control-Allow-Methods', 'OPTIONS, GET');
$response->setHeader('Cache-Control', 'no-store');
$authz = $this->ctx->getAuthzContext();
if(!$authz->hasScope('identify'))
return 403;