Change to ->container->environment
This commit is contained in:
parent
676571dab9
commit
d8ef4a893f
1 changed files with 10 additions and 18 deletions
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
use Shaarli\Api\Exceptions\ApiAuthorizationException;
|
use Shaarli\Api\Exceptions\ApiAuthorizationException;
|
||||||
use Shaarli\Api\Exceptions\ApiException;
|
use Shaarli\Api\Exceptions\ApiException;
|
||||||
use Shaarli\Bookmark\BookmarkFileService;
|
|
||||||
use Shaarli\Config\ConfigManager;
|
use Shaarli\Config\ConfigManager;
|
||||||
use Slim\Container;
|
use Slim\Container;
|
||||||
use Slim\Http\Request;
|
use Slim\Http\Request;
|
||||||
|
@ -71,14 +70,7 @@ public function __invoke($request, $response, $next)
|
||||||
$response = $e->getApiResponse();
|
$response = $e->getApiResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $response
|
return $response;
|
||||||
->withHeader('Access-Control-Allow-Origin', '*')
|
|
||||||
->withHeader(
|
|
||||||
'Access-Control-Allow-Headers',
|
|
||||||
'X-Requested-With, Content-Type, Accept, Origin, Authorization'
|
|
||||||
)
|
|
||||||
->withHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS')
|
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -107,7 +99,7 @@ protected function checkRequest($request)
|
||||||
*/
|
*/
|
||||||
protected function checkToken($request)
|
protected function checkToken($request)
|
||||||
{
|
{
|
||||||
if (! $request->hasHeader('Authorization') && !isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION'])) {
|
if (! $request->hasHeader('Authorization') && !isset($this->container->environment['REDIRECT_HTTP_AUTHORIZATION'])) {
|
||||||
throw new ApiAuthorizationException('JWT token not provided');
|
throw new ApiAuthorizationException('JWT token not provided');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,8 +107,8 @@ protected function checkToken($request)
|
||||||
throw new ApiAuthorizationException('Token secret must be set in Shaarli\'s administration');
|
throw new ApiAuthorizationException('Token secret must be set in Shaarli\'s administration');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION'])) {
|
if (isset($this->container->environment['REDIRECT_HTTP_AUTHORIZATION'])) {
|
||||||
$authorization = $_SERVER['REDIRECT_HTTP_AUTHORIZATION'];
|
$authorization = $this->container->environment['REDIRECT_HTTP_AUTHORIZATION'];
|
||||||
} else {
|
} else {
|
||||||
$authorization = $request->getHeaderLine('Authorization');
|
$authorization = $request->getHeaderLine('Authorization');
|
||||||
}
|
}
|
||||||
|
@ -129,7 +121,7 @@ protected function checkToken($request)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiate a new LinkDB including private bookmarks,
|
* Instantiate a new LinkDB including private links,
|
||||||
* and load in the Slim container.
|
* and load in the Slim container.
|
||||||
*
|
*
|
||||||
* FIXME! LinkDB could use a refactoring to avoid this trick.
|
* FIXME! LinkDB could use a refactoring to avoid this trick.
|
||||||
|
@ -138,10 +130,10 @@ protected function checkToken($request)
|
||||||
*/
|
*/
|
||||||
protected function setLinkDb($conf)
|
protected function setLinkDb($conf)
|
||||||
{
|
{
|
||||||
$linkDb = new BookmarkFileService(
|
$linkDb = new \Shaarli\Bookmark\LinkDB(
|
||||||
$conf,
|
$conf->get('resource.datastore'),
|
||||||
$this->container->get('history'),
|
true,
|
||||||
true
|
$conf->get('privacy.hide_public_links')
|
||||||
);
|
);
|
||||||
$this->container['db'] = $linkDb;
|
$this->container['db'] = $linkDb;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue