mirror of
https://github.com/nextcloud/passman.git
synced 2025-12-16 05:02:45 +08:00
Fix cors headers
This commit is contained in:
parent
2a793870ac
commit
d509bbd160
9 changed files with 70 additions and 7 deletions
|
|
@ -47,7 +47,12 @@ class CredentialController extends ApiController {
|
||||||
SettingsService $settings
|
SettingsService $settings
|
||||||
|
|
||||||
) {
|
) {
|
||||||
parent::__construct($AppName, $request);
|
parent::__construct(
|
||||||
|
$AppName,
|
||||||
|
$request,
|
||||||
|
'GET, POST, DELETE, PUT, PATCH, OPTIONS',
|
||||||
|
'Authorization, Content-Type, Accept',
|
||||||
|
86400);
|
||||||
$this->userId = $userId;
|
$this->userId = $userId;
|
||||||
$this->credentialService = $credentialService;
|
$this->credentialService = $credentialService;
|
||||||
$this->activityService = $activityService;
|
$this->activityService = $activityService;
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,12 @@ class FileController extends ApiController {
|
||||||
IRequest $request,
|
IRequest $request,
|
||||||
$UserId,
|
$UserId,
|
||||||
FileService $fileService){
|
FileService $fileService){
|
||||||
parent::__construct($AppName, $request);
|
parent::__construct(
|
||||||
|
$AppName,
|
||||||
|
$request,
|
||||||
|
'GET, POST, DELETE, PUT, PATCH, OPTIONS',
|
||||||
|
'Authorization, Content-Type, Accept',
|
||||||
|
86400);
|
||||||
$this->userId = $UserId;
|
$this->userId = $UserId;
|
||||||
$this->fileService = $fileService;
|
$this->fileService = $fileService;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,12 @@ class InternalController extends ApiController {
|
||||||
CredentialService $credentialService,
|
CredentialService $credentialService,
|
||||||
IConfig $config
|
IConfig $config
|
||||||
) {
|
) {
|
||||||
parent::__construct($AppName, $request);
|
parent::__construct(
|
||||||
|
$AppName,
|
||||||
|
$request,
|
||||||
|
'GET, POST, DELETE, PUT, PATCH, OPTIONS',
|
||||||
|
'Authorization, Content-Type, Accept',
|
||||||
|
86400);
|
||||||
$this->userId = $UserId;
|
$this->userId = $UserId;
|
||||||
$this->credentialService = $credentialService;
|
$this->credentialService = $credentialService;
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,12 @@ class SettingsController extends ApiController {
|
||||||
$userId,
|
$userId,
|
||||||
SettingsService $settings,
|
SettingsService $settings,
|
||||||
IL10N $l) {
|
IL10N $l) {
|
||||||
parent::__construct($AppName, $request);
|
parent::__construct(
|
||||||
|
$AppName,
|
||||||
|
$request,
|
||||||
|
'GET, POST, DELETE, PUT, PATCH, OPTIONS',
|
||||||
|
'Authorization, Content-Type, Accept',
|
||||||
|
86400);
|
||||||
$this->settings = $settings;
|
$this->settings = $settings;
|
||||||
$this->l = $l;
|
$this->l = $l;
|
||||||
$this->userId = $userId;
|
$this->userId = $userId;
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,12 @@ class ShareController extends ApiController {
|
||||||
FileService $fileService,
|
FileService $fileService,
|
||||||
SettingsService $config
|
SettingsService $config
|
||||||
) {
|
) {
|
||||||
parent::__construct($AppName, $request);
|
parent::__construct(
|
||||||
|
$AppName,
|
||||||
|
$request,
|
||||||
|
'GET, POST, DELETE, PUT, PATCH, OPTIONS',
|
||||||
|
'Authorization, Content-Type, Accept',
|
||||||
|
86400);
|
||||||
|
|
||||||
$this->userId = $UserId;
|
$this->userId = $UserId;
|
||||||
$this->userManager = $userManager;
|
$this->userManager = $userManager;
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,12 @@ class TranslationController extends ApiController {
|
||||||
IRequest $request,
|
IRequest $request,
|
||||||
IL10N $trans
|
IL10N $trans
|
||||||
) {
|
) {
|
||||||
parent::__construct($AppName, $request);
|
parent::__construct(
|
||||||
|
$AppName,
|
||||||
|
$request,
|
||||||
|
'GET, POST, DELETE, PUT, PATCH, OPTIONS',
|
||||||
|
'Authorization, Content-Type, Accept',
|
||||||
|
86400);
|
||||||
$this->trans = $trans;
|
$this->trans = $trans;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ class VaultController extends ApiController {
|
||||||
parent::__construct(
|
parent::__construct(
|
||||||
$AppName,
|
$AppName,
|
||||||
$request,
|
$request,
|
||||||
'GET, POST, DELETE, PUT, PATCH',
|
'GET, POST, DELETE, PUT, PATCH, OPTIONS',
|
||||||
'Authorization, Content-Type, Accept',
|
'Authorization, Content-Type, Accept',
|
||||||
86400);
|
86400);
|
||||||
$this->userId = $UserId;
|
$this->userId = $UserId;
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ use OCA\Passman\Controller\CredentialController;
|
||||||
use OCA\Passman\Controller\PageController;
|
use OCA\Passman\Controller\PageController;
|
||||||
use OCA\Passman\Controller\ShareController;
|
use OCA\Passman\Controller\ShareController;
|
||||||
use OCA\Passman\Controller\VaultController;
|
use OCA\Passman\Controller\VaultController;
|
||||||
|
use OCA\Passman\Middleware\APIMiddleware;
|
||||||
use OCA\Passman\Middleware\ShareMiddleware;
|
use OCA\Passman\Middleware\ShareMiddleware;
|
||||||
use OCA\Passman\Service\ActivityService;
|
use OCA\Passman\Service\ActivityService;
|
||||||
use OCA\Passman\Service\CronService;
|
use OCA\Passman\Service\CronService;
|
||||||
|
|
@ -109,6 +110,8 @@ class Application extends App {
|
||||||
return $c->query('ServerContainer')->getLogger();
|
return $c->query('ServerContainer')->getLogger();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$container->registerMiddleware('APIMiddleware');
|
||||||
|
|
||||||
// Aliases for the controllers so we can use the automatic DI
|
// Aliases for the controllers so we can use the automatic DI
|
||||||
$container->registerAlias('CredentialController', CredentialController::class);
|
$container->registerAlias('CredentialController', CredentialController::class);
|
||||||
$container->registerAlias('PageController', PageController::class);
|
$container->registerAlias('PageController', PageController::class);
|
||||||
|
|
@ -124,6 +127,7 @@ class Application extends App {
|
||||||
$container->registerAlias('IDBConnection', IDBConnection::class);
|
$container->registerAlias('IDBConnection', IDBConnection::class);
|
||||||
$container->registerAlias('IConfig', IConfig::class);
|
$container->registerAlias('IConfig', IConfig::class);
|
||||||
$container->registerAlias('SettingsService', SettingsService::class);
|
$container->registerAlias('SettingsService', SettingsService::class);
|
||||||
|
$container->registerAlias('APIMiddleware', APIMiddleware::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
29
middleware/apimiddleware.php
Normal file
29
middleware/apimiddleware.php
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace OCA\Passman\Middleware;
|
||||||
|
|
||||||
|
use OCP\AppFramework\Http\JSONResponse;
|
||||||
|
use OCP\AppFramework\Http\Response;
|
||||||
|
use \OCP\AppFramework\Middleware;
|
||||||
|
use OCP\IRequest;
|
||||||
|
|
||||||
|
class APIMiddleware extends Middleware {
|
||||||
|
|
||||||
|
private $request;
|
||||||
|
|
||||||
|
public function __construct(IRequest $request) {
|
||||||
|
$this->request = $request;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function afterController($controller, $methodName, Response $response) {
|
||||||
|
if($response instanceof JSONResponse){
|
||||||
|
$origin = $this->request->server['HTTP_ORIGIN'];
|
||||||
|
if($origin) {
|
||||||
|
$response->addHeader('Access-Control-Allow-Origin', $origin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return parent::afterController($controller, $methodName, $response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Loading…
Add table
Reference in a new issue