Commit 49b4b93d authored by Aster's avatar Aster Committed by waltermazza
Browse files

General Bug Fixes and Improvements

parent d1ca7edd
{ {
"name": "arter/amos-social-auth", "name": "arter/amos-social-auth",
"description": "Social Auth", "description": "Social Auth",
"keywords": [ "keywords": ["amos", "auth", "social", "yii2"],
"amos",
"auth",
"social",
"yii2"
],
"homepage": "https://bitbucket.org/arter/amos-social-auth", "homepage": "https://bitbucket.org/arter/amos-social-auth",
"type": "component", "type": "component",
"require": { "require": {
"php": ">=5.4.0", "php": ">=5.4.0",
"arter/amos-admin": "^2.0.18", "arter/amos-admin":"^2.0.18",
"arter/amos-core": "^1.9.52", "arter/amos-core":"^1.9.52",
"arter/amos-attachments": "^1.0", "arter/amos-attachments":"^1.0",
"hybridauth/hybridauth": "~2.9", "hybridauth/hybridauth": "~2.9",
"google/apiclient": "^2.0" "google/apiclient": "^2.0",
"yiisoft/yii2-authclient": "^2.1.0",
"conquer/oauth2": "*"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* EROI - Emilia Romagna Open Innovation is based on: * EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it * https://www.open2.0.regione.lombardia.it
* *
* @see https://repo.art-er.it Developers' community * @see http://example.com Developers'community
* @license GPLv3 * @license GPLv3
* @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 * @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3
* *
...@@ -16,11 +16,14 @@ ...@@ -16,11 +16,14 @@
namespace arter\amos\socialauth; namespace arter\amos\socialauth;
use arter\amos\admin\AmosAdmin; use arter\amos\admin\AmosAdmin;
use arter\amos\admin\models\UserProfile;
use arter\amos\core\module\AmosModule; use arter\amos\core\module\AmosModule;
use arter\amos\socialauth\controllers\ShibbolethController; use arter\amos\socialauth\controllers\ShibbolethController;
use arter\amos\socialauth\models\SocialAuthServices; use arter\amos\socialauth\models\SocialAuthServices;
use arter\amos\socialauth\utility\SocialAuthUtility;
use Yii; use Yii;
use yii\base\BootstrapInterface; use yii\base\BootstrapInterface;
use yii\base\Event;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
/** /**
...@@ -46,6 +49,11 @@ class Module extends AmosModule implements BootstrapInterface ...@@ -46,6 +49,11 @@ class Module extends AmosModule implements BootstrapInterface
*/ */
public $enableSpid = false; public $enableSpid = false;
public $shibbolethConfig = [
'buttonLabel' => '#fullsize_login_spid_text',
'buttonDescription' => '#fullsize_login_spid_text_right'
];
/** /**
* @var $enableLogin bool Is Social Account Link Enabled? * @var $enableLogin bool Is Social Account Link Enabled?
*/ */
...@@ -95,6 +103,16 @@ class Module extends AmosModule implements BootstrapInterface ...@@ -95,6 +103,16 @@ class Module extends AmosModule implements BootstrapInterface
*/ */
public $enableSpidMultiUsersSameCF = false; public $enableSpidMultiUsersSameCF = false;
/**
* @var bool $shibbolethAutoLogin if true on shibboleth controller make automatic login
*/
public $shibbolethAutoLogin = false;
/**
* @var bool $shibbolethAutoRegistration if true on shibboleth controller make automatic registration
*/
public $shibbolethAutoRegistration = false;
/** /**
* @inheritdoc * @inheritdoc
*/ */
...@@ -108,6 +126,17 @@ class Module extends AmosModule implements BootstrapInterface ...@@ -108,6 +126,17 @@ class Module extends AmosModule implements BootstrapInterface
\Yii::configure($this, ArrayHelper::merge($config, $this)); \Yii::configure($this, ArrayHelper::merge($config, $this));
} }
/**
* @inheritdoc
*/
public static function getInstance() {
if(Yii::$app->session->has('socialAuthInstance')) {
return Yii::$app->getModule(Yii::$app->session->get('socialAuthInstance'));
}
return parent::getInstance();
}
/** /**
* @return array * @return array
*/ */
...@@ -276,6 +305,8 @@ class Module extends AmosModule implements BootstrapInterface ...@@ -276,6 +305,8 @@ class Module extends AmosModule implements BootstrapInterface
//Init a new shibboleth controller to link user //Init a new shibboleth controller to link user
$shibbolethController = new ShibbolethController('shibboleth', $this); $shibbolethController = new ShibbolethController('shibboleth', $this);
Event::on(AmosAdmin::instance()->model('UserProfile'), UserProfile::EVENT_AFTER_INSERT, ['arter\amos\socialauth\utility\SocialAuthUtility', 'createIdmUser']);
//Get Session IDM datas (copy of headers) //Get Session IDM datas (copy of headers)
$sessionIDM = \Yii::$app->session->get('IDM'); $sessionIDM = \Yii::$app->session->get('IDM');
......
...@@ -4,11 +4,11 @@ ...@@ -4,11 +4,11 @@
* EROI - Emilia Romagna Open Innovation is based on: * EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it * https://www.open2.0.regione.lombardia.it
* *
* @see https://repo.art-er.it Developers' community * @see http://example.com Developers'community
* @license GPLv3 * @license GPLv3
* @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 * @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3
* *
* @package arter\amos\socialauth\components * @package arter\amos\socialauth
* @category CategoryName * @category CategoryName
* @author Elite Division S.r.l. * @author Elite Division S.r.l.
*/ */
......
...@@ -4,11 +4,11 @@ ...@@ -4,11 +4,11 @@
* EROI - Emilia Romagna Open Innovation is based on: * EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it * https://www.open2.0.regione.lombardia.it
* *
* @see https://repo.art-er.it Developers' community * @see http://example.com Developers'community
* @license GPLv3 * @license GPLv3
* @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 * @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3
* *
* @package arter\amos\socialauth\components * @package arter\amos\socialauth
* @category CategoryName * @category CategoryName
* @author Elite Division S.r.l. * @author Elite Division S.r.l.
*/ */
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* EROI - Emilia Romagna Open Innovation is based on: * EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it * https://www.open2.0.regione.lombardia.it
* *
* @see https://repo.art-er.it Developers' community * @see http://example.com Developers'community
* @license GPLv3 * @license GPLv3
* @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 * @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3
* *
......
...@@ -4,11 +4,11 @@ ...@@ -4,11 +4,11 @@
* EROI - Emilia Romagna Open Innovation is based on: * EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it * https://www.open2.0.regione.lombardia.it
* *
* @see https://repo.art-er.it Developers' community * @see http://example.com Developers'community
* @license GPLv3 * @license GPLv3
* @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 * @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3
* *
* @package arter\amos\socialauth\components * @package arter\amos\socialauth
* @category CategoryName * @category CategoryName
* @author Elite Division S.r.l. * @author Elite Division S.r.l.
*/ */
......
...@@ -4,11 +4,11 @@ ...@@ -4,11 +4,11 @@
* EROI - Emilia Romagna Open Innovation is based on: * EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it * https://www.open2.0.regione.lombardia.it
* *
* @see https://repo.art-er.it Developers' community * @see http://example.com Developers'community
* @license GPLv3 * @license GPLv3
* @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 * @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3
* *
* @package arter\amos\socialauth\components\views * @package arter\amos\socialauth
* @category CategoryName * @category CategoryName
* @author Elite Division S.r.l. * @author Elite Division S.r.l.
*/ */
......
...@@ -4,11 +4,11 @@ ...@@ -4,11 +4,11 @@
* EROI - Emilia Romagna Open Innovation is based on: * EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it * https://www.open2.0.regione.lombardia.it
* *
* @see https://repo.art-er.it Developers' community * @see http://example.com Developers'community
* @license GPLv3 * @license GPLv3
* @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 * @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3
* *
* @package arter\amos\socialauth\components\views * @package arter\amos\socialauth
* @category CategoryName * @category CategoryName
* @author Elite Division S.r.l. * @author Elite Division S.r.l.
*/ */
......
...@@ -4,11 +4,11 @@ ...@@ -4,11 +4,11 @@
* EROI - Emilia Romagna Open Innovation is based on: * EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it * https://www.open2.0.regione.lombardia.it
* *
* @see https://repo.art-er.it Developers' community * @see http://example.com Developers'community
* @license GPLv3 * @license GPLv3
* @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 * @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3
* *
* @package arter\amos\socialauth\components\views * @package arter\amos\socialauth
* @category CategoryName * @category CategoryName
* @author Elite Division S.r.l. * @author Elite Division S.r.l.
*/ */
......
...@@ -4,11 +4,11 @@ ...@@ -4,11 +4,11 @@
* EROI - Emilia Romagna Open Innovation is based on: * EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it * https://www.open2.0.regione.lombardia.it
* *
* @see https://repo.art-er.it Developers' community * @see http://example.com Developers'community
* @license GPLv3 * @license GPLv3
* @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 * @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3
* *
* @package arter\amos\socialauth\components\views * @package arter\amos\socialauth
* @category CategoryName * @category CategoryName
* @author Elite Division S.r.l. * @author Elite Division S.r.l.
*/ */
......
...@@ -4,11 +4,11 @@ ...@@ -4,11 +4,11 @@
* EROI - Emilia Romagna Open Innovation is based on: * EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it * https://www.open2.0.regione.lombardia.it
* *
* @see https://repo.art-er.it Developers' community * @see http://example.com Developers'community
* @license GPLv3 * @license GPLv3
* @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 * @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3
* *
* @package arter\amos\socialauth\config * @package arter\amos\socialauth
* @category CategoryName * @category CategoryName
* @author Elite Division S.r.l. * @author Elite Division S.r.l.
*/ */
......
<?php
/**
* Copyright 2020 Art-ER S. Cons. P.A.
* EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it
*
* @see http://example.com Developers'community
* @license GPLv3
* @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3
*
* @package arter\amos\socialauth
* @category CategoryName
* @author Elite Division S.r.l.
*/
namespace arter\amos\socialauth\controllers;
use conquer\oauth2\models\Client;
use arter\amos\admin\models\LoginForm;
use arter\amos\admin\models\UserProfile;
use arter\amos\core\controllers\CrudController;
use arter\amos\core\helpers\Html;
use arter\amos\core\icons\AmosIcons;
use arter\amos\socialauth\models\search\ClientSearch;
use arter\amos\socialauth\Module;
use Yii;
use yii\filters\AccessControl;
use yii\web\Response;
class Oauth2Controller extends CrudController
{
/**
* @var string $layout
*/
public $layout = 'login';
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'allow' => true,
'actions' => [
'token',
'back',
'auth',
'userinfo',
'index',
],
//'roles' => ['*']
],
[
'allow' => true,
'actions' => [
'manage',
],
'roles' => ['ADMIN']
]
],
],
'oauth2Auth' => [
'class' => \conquer\oauth2\AuthorizeFilter::className(),
'only' => ['auth'],
'allowImplicit' => false
],
'tokenAuth' => [
'class' => \conquer\oauth2\TokenAuth::className(),
'only' => ['userinfo'],
],
];
}
/**
* @inheritdoc
*/
public function init()
{
$this->setModelObj(new Client());
$this->setModelSearch(new ClientSearch());
$this->setAvailableViews(
[
'grid' => [
'name' => 'grid',
'label' => Module::t(
'amosdiscussioni',
'{iconaTabella}' . Html::tag('p', Module::t('amosdiscussioni', 'Table')),
[
'iconaTabella' => AmosIcons::show('view-list-alt')
]
),
'url' => '?currentView=grid'
],
]
);
parent::init();
$this->setUpLayout();
// custom initialization code goes here
}
public function beforeAction($action)
{
if ($action->id == 'userinfo') {
Yii::$app->response->format = Response::FORMAT_JSON;
}
return parent::beforeAction($action);
}
public function actions()
{
return [
/**
* Returns an access token.
*/
'token' => [
'class' => \conquer\oauth2\TokenAction::classname(),
],
/**
* OPTIONAL
* Third party oauth providers also can be used.
*/
'back' => [
'class' => \yii\authclient\AuthAction::className(),
'successCallback' => [$this, 'successCallback'],
],
];
}
public function actionManage($layout = null)
{
$this->setUpLayout('list');
//se il layout di default non dovesse andar bene si può aggiuntere il layout desiderato
//in questo modo nel controller "return parent::actionIndex($this->layout);"
if ($layout) {
$this->setUpLayout($layout);
}
return $this->render(
'index',
[
'dataProvider' => $this->getDataProvider(),
'model' => $this->getModelSearch(),
'currentView' => $this->getCurrentView(),
'availableViews' => $this->getAvailableViews(),
'url' => ($this->url) ? $this->url : null,
'parametro' => ($this->parametro) ? $this->parametro : null
]
);
}
/**
* Display login form, signup or something else.
* AuthClients such as Google also may be used
*/
public function actionAuth()
{
$model = new LoginForm();
if (Yii::$app->request->isPost && $model->load(\Yii::$app->request->post()) && $model->login()) {
if ($this->isOauthRequest) {
$this->finishAuthorization();
} else {
return $this->goBack();
}
} else {
return $this->render(
'login',
[
'model' => $model,
]
);
}
}
public function actionUserinfo($access_token)
{
$userProfile = UserProfile::findOne(Yii::$app->user->id);
return [
'sub' => $userProfile->id,
'given_name' => $userProfile->user->username,
'family_name' => $userProfile->cognome,
'name' => $userProfile->nome,
'picture' => $userProfile ? $userProfile->getAvatarWebUrl() : null,
'profile' => '',
'gender' => $userProfile->sesso,
'locale' => $userProfile->language,
'email' => $userProfile->user->email
];
}
}
...@@ -4,26 +4,28 @@ ...@@ -4,26 +4,28 @@
* EROI - Emilia Romagna Open Innovation is based on: * EROI - Emilia Romagna Open Innovation is based on:
* https://www.open2.0.regione.lombardia.it * https://www.open2.0.regione.lombardia.it
* *
* @see https://repo.art-er.it Developers' community * @see http://example.com Developers'community
* @license GPLv3 * @license GPLv3
* @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 * @license https://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3
* *
* @package arter\amos\socialauth\controllers * @package arter\amos\socialauth
* @category CategoryName * @category CategoryName
* @author Elite Division S.r.l. * @author Elite Division S.r.l.
*/ */
namespace arter\amos\socialauth\controllers; namespace arter\amos\socialauth\controllers;
use arter\amos\admin\AmosAdmin;
use arter\amos\admin\models\UserProfile; use arter\amos\admin\models\UserProfile;
use arter\amos\core\controllers\BackendController; use arter\amos\core\controllers\BackendController;
use arter\amos\core\user\User; use arter\amos\core\user\User;
use arter\amos\socialauth\models\SocialIdmUser; use arter\amos\socialauth\models\SocialIdmUser;
use arter\amos\socialauth\Module; use arter\amos\socialauth\Module;
use arter\amos\socialauth\utility\SocialAuthUtility; use arter\amos\socialauth\utility\SocialAuthUtility;
use http\Exception\RuntimeException;
use yii\filters\AccessControl;
use Yii; use Yii;
use yii\base\Action;
use yii\filters\AccessControl;
use yii\helpers\Url;
/** /**
* Class ShibbolethController * Class ShibbolethController
...@@ -31,6 +33,8 @@ use Yii; ...@@ -31,6 +33,8 @@ use Yii;
*/ */
class ShibbolethController extends BackendController class ShibbolethController extends BackendController
{ {
const LOGGED_WITH_SPID_SESSION_ID = 'logged_with_spid_user_id';
/** /**
* @var string $layout * @var string $layout
*/ */
...@@ -56,6 +60,7 @@ class ShibbolethController extends BackendController ...@@ -56,6 +60,7 @@ class ShibbolethController extends BackendController
'endpoint', 'endpoint',
'mobile', 'mobile',
'sign-up', 'sign-up',
'set-module-instance',
], ],
//'roles' => ['*'] //'roles' => ['*']
] ]
...@@ -101,7 +106,7 @@ class ShibbolethController extends BackendController ...@@ -101,7 +106,7 @@ class ShibbolethController extends BackendController
{ {
$result = $this->tryIdmLink(false, true, false); $result = $this->tryIdmLink(false, true, false);
if(is_array($result) && isset($result['status'])) { if (is_array($result) && isset($result['status'])) {
$user = \arter\amos\mobile\bridge\modules\v1\models\User::findOne(Yii::$app->user->id); $user = \arter\amos\mobile\bridge\modules\v1\models\User::findOne(Yii::$app->user->id);
$user->refreshAccessToken('', ''); $user->refreshAccessToken('', '');
...@@ -119,21 +124,39 @@ class ShibbolethController extends BackendController ...@@ -119,21 +124,39 @@ class ShibbolethController extends BackendController
public function tryIdmLink($confirmLink = false, $render = true, $redirect = true) public function tryIdmLink($confirmLink = false, $render = true, $redirect = true)