我正在做Magento模块以进行Auth0登录。我正在使用Auth0 php lib,我在使用composer的lib文件夹下拥有该文件。与观察者,我正在自动加载此PHP库。我可以使用模块控制器的操作来调用url,然后它将检查用户是否已加载Auth0,如果是,它将检查该电子邮件中是否有Magento用户并登录。但是我想使它自动执行,因此当有人访问我的Magento电子商店时,它将检查Auth0并自动登录。我怎样才能做到这一点 ?我尝试与观察者,但没有成功,不确定我应该使用哪个事件。谢谢
使用观察者自动加载Auth0 php lib的示例:
public static function controllerFrontInitBefore(Varien_Event_Observer $event) {
self::init();
}
static function init()
{
// Add our vendor folder to our include path
set_include_path(get_include_path() . PATH_SEPARATOR . Mage::getBaseDir('lib') . DS . 'MyCompany' . DS . 'Sso' . DS . 'vendor');
// Include the autoloader for composer
require_once(Mage::getBaseDir('lib') . DS . 'MyCompany' . DS . 'Sso' . DS . 'vendor' . DS . 'autoload.php');
}
控制器动作的示例(我需要在每个页面上自动调用):
public function checkAction()
{
$domain = '***.eu.auth0.com';
$clientId = '***';
$clientSecret = '***';
$audience = 'https://***.eu.auth0.com/userinfo';
$redirectUri = 'http://***/sso/index/check';
$auth0 = new Auth0([
// See Installation above to setup environment variables.
'domain' => $domain,
'client_id' => $clientId,
'client_secret' => $clientSecret,
'audience' => $audience,
'redirect_uri' => $redirectUri,
// The scope determines what data is provided by the /userinfo endpoint.
// There must be at least one valid scope included here for anything to be returned from /userinfo.
'scope' => 'openid profile',
'persist_id_token' => true,
'persist_access_token' => true,
'persist_refresh_token' => true
]);
$userInfo = $auth0->getUser();
if (empty($userInfo)) {
$auth0->login();
} else {
//login magento user
}