Files
Phraseanet/lib/classes/patch/417PHRAS2995.php
jygaulier 7e7435469d PHRAS-2995_phr-as-auth-idp-BIS (#4180)
* WIP ; allow multiple instances of some auth clients (migrate conf) ; add ps-oauth ; remove google+

* WIP ; fix ps-oauth ; fix tests

* WIP ; add api-auth to extra_hosts

* WIP ; fix yaml syntax error

* WIP ; fix yaml syntax error ; better conf sample

* WIP ; add "everyone-group"

* WIP ; add the provider-id in session

* WIP ; add getOptions() to providers (so phr/expose can filter providers)

* WIP ; add auto-logout option so logout from phr also logouts from ps-auth

* connect to expose using IDP from connected user

* WIP ; auto-logout redirects to phr home

* unnecessary session var

* unused

* fix

* catch some error

* fix navigation in train thumbnail

* update file version

* pass params in session to have constant redirect_uri ; add debug

* invalidate session --> parade test ok

* cleanup
2022-12-01 16:27:54 +01:00

115 lines
3.2 KiB
PHP

<?php
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Core\Configuration\PropertyAccess;
class patch_417PHRAS2995 implements patchInterface
{
/** @var string */
private $release = '4.1.7-rc1';
/** @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 [];
}
/**
* {@inheritdoc}
*/
public function apply(base $appbox, Application $app)
{
$id2title = [
'facebook' => 'Facebook',
'github' => 'Github',
'linkedin' => 'LinkedIn',
'phraseanet' => 'Phraseanet',
'twitter' => 'Twitter',
'viadeo' => 'Viadeo'
];
/** @var PropertyAccess $conf */
$conf = $app['conf'];
$newProviders = [];
$psFound = false;
foreach ($app['conf']->get(['authentication', 'providers'], []) as $providerId => $data) {
if($providerId === 'google-plus') { // rip
continue;
}
if(array_key_exists('type', $data)) {
// already good format
$newProviders[$providerId] = $data;
if($data['type'] === "ps-auth") {
$psFound = true;
}
}
else {
// bump format
$newProviders[$providerId] = [
'enabled' => $data['enabled'],
'display' => $data['enabled'],
'title' => array_key_exists($providerId, $id2title) ? $id2title[$providerId] : $providerId,
'type' => $providerId,
'options' => $data['options']
];
}
}
// add ps
if(!$psFound && !array_key_exists('ps-auth-1', $newProviders)) {
$newProviders['ps-auth-1'] = [
'enabled' => false,
'display' => false,
'title' => 'PS Auth',
'type' => 'ps-auth',
'options' => [
'client-id' => 'client_id',
'client-secret' => 'client_secret',
'base-url' => 'https://api-auth.phrasea.local',
'provider-type' => 'oauth',
'provider-name' => 'v2',
'icon-uri' => null,
'birth-group' => '_firstlog',
'everyone-group' => '_everyone',
'metamodel' => '_metamodel',
'model-gpfx' => '_M_',
'model-upfx' => '_U_',
'auto-logout' => false
]
];
}
$conf->set(['authentication', 'providers'], $newProviders);
return true;
}
}