change behavior api_token_header

This commit is contained in:
aynsix
2020-08-05 19:57:53 +03:00
parent f6854caaba
commit 2e1ce43321
9 changed files with 88 additions and 15 deletions

View File

@@ -6,8 +6,6 @@ main:
maintenance: false
languages: []
key: ''
api_require_ssl: true
api_token_header: false
delete-account-require-email-confirmation: true
database:
host: 127.0.0.1
@@ -232,6 +230,10 @@ api_cors_paths: []
session:
idle: 0
lifetime: 604800 # 1 week
registry:
api-clients:
api_require_ssl: false
api_token_header_only: false
crossdomain:
site-control: 'master-only'
allow-access-from:

View File

@@ -52,7 +52,7 @@ bin/setup system:config set workers.queue.worker-queue.vhost /
## enable API and disable ssl on it
/var/alchemy/Phraseanet/bin/setup system:config set registry.api-clients.api-enabled $PHRASEANET_API_ENABLED
/var/alchemy/Phraseanet/bin/setup system:config set main.api_require_ssl $PHRASEANET_API_SSL
/var/alchemy/Phraseanet/bin/setup system:config set registry.api-clients.api_require_ssl $PHRASEANET_API_SSL
# set instance title
bin/setup system:config set registry.general.title $PHRASEANET_PROJECT_NAME

View File

@@ -282,7 +282,7 @@ class OAuth2Controller extends Controller
/** @var PropertyAccess $config */
$config = $this->app['conf'];
if ( ! $request->isSecure() && $config->get(['main', 'api_require_ssl'], true) == true) {
if ( ! $request->isSecure() && $config->get(['registry', 'api-clients', 'api_require_ssl'], true) == true) {
throw new HttpException(400, 'This route requires the use of the https scheme: ' . $config->get(['main', 'api_require_ssl']), null, ['content-type' => 'application/json']);
}

View File

@@ -16,7 +16,7 @@ class Version
/**
* @var string
*/
private $number = '4.1.1';
private $number = '4.1.2';
/**
* @var string

View File

@@ -537,7 +537,7 @@ class API_OAuth2_Adapter extends OAuth2
public function verifyAccessToken($scope = null, $exit_not_present = true, $exit_invalid = true, $exit_expired = true, $exit_scope = true, $realm = null)
{
$apiTokenHeader = $this->app['conf']->get(['main', 'api_token_header']);
$apiTokenHeader = $this->app['conf']->get(['registry', 'api-clients', 'api_token_header_only']);
$useTokenHeader = $this->useTokenHeaderChoice($apiTokenHeader);
@@ -816,15 +816,13 @@ class API_OAuth2_Adapter extends OAuth2
/**
* Get the correct constante to call on Oauth2
*
* @param $apiTokenHeader
* @param $apiTokenHeaderOnly
* @return string
*/
private function useTokenHeaderChoice($apiTokenHeader)
private function useTokenHeaderChoice($apiTokenHeaderOnly)
{
if ($apiTokenHeader === true) {
if ($apiTokenHeaderOnly === true) {
return Oauth2::TOKEN_ONLY_IN_HEADER;
} elseif ($apiTokenHeader === false) {
return Oauth2::TOKEN_ONLY_IN_GETPOST;
} else {
return Oauth2::TOKEN_AUTO_FIND;
}

76
lib/classes/patch/412.php Normal file
View File

@@ -0,0 +1,76 @@
<?php
use Alchemy\Phrasea\Application;
class patch_412 implements patchInterface
{
/** @var string */
private $release = '4.1.2';
/** @var array */
private $concern = [base::APPLICATION_BOX];
/**
* Returns the release version.
*
* @return string
*/
public function get_release()
{
return $this->release;
}
/**
* {@inheritdoc}
*/
public function concern()
{
return $this->concern;
}
/**
* {@inheritdoc}
*/
public function require_all_upgrades()
{
return false;
}
/**
* {@inheritdoc}
*/
public function getDoctrineMigrations()
{
return [];
}
/**
* Apply patch.
*
* @param base $base The Application Box or the Data Boxes where the patch is applied.
* @param \Alchemy\Phrasea\Application $app
*
* @return boolean returns true if the patch succeed.
*/
public function apply(base $appbox, Application $app)
{
// move api_require_ssl place in configuration.yml
if ($app['conf']->has(['main', 'api_require_ssl'])) {
$apiRequireSslValue = $app['conf']->get(['main', 'api_require_ssl']);
$app['conf']->remove(['main', 'api_require_ssl']);
$app['conf']->set(['registry', 'api-clients', 'api_require_ssl'], $apiRequireSslValue);
}
// change api_token_header place and name in configuration.yml
if ($app['conf']->has(['main', 'api_token_header'])) {
$apiTokenHeaderValue = $app['conf']->get(['main', 'api_token_header']);
$app['conf']->remove(['main', 'api_token_header']);
$app['conf']->set(['registry', 'api-clients', 'api_token_header_only'], $apiTokenHeaderValue);
}
// add svg in extension-mapping
if (!$app['conf']->has(['border-manager', 'extension-mapping', 'svg'])) {
$app['conf']->set(['border-manager', 'extension-mapping', 'svg'], 'image/svg+xml');
}
}
}

View File

@@ -9,8 +9,6 @@ languages:
main:
maintenance: false
key: ''
api_require_ssl: true
api_token_header: false
database:
host: 'sql-host'
port: 3306

View File

@@ -50,7 +50,7 @@
chdir: /vagrant/
- name: Disable API SSL requirement
shell: php bin/setup system:config set main.api_require_ssl false
shell: php bin/setup system:config set registry.api-clients.api_require_ssl false
args:
chdir: /vagrant/

View File

@@ -5,7 +5,6 @@ languages:
main:
maintenance: false
key: ''
api_require_ssl: true
delete-account-require-email-confirmation: true
database:
host: 'sql-host'