function AuthJUser() { if (!class_exists('Auth0Connect')) { require_once JPATH_COMPONENT . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'auth0_connect.php'; } $params = JComponentHelper::getParams('com_auth0'); $clientid = $params->get('clientid'); $clientsecret = $params->get('clientsecret'); $domain = 'https://' . $params->get('domain'); $this->app = JFactory::getApplication('site'); $code = $this->app->input->getVar('code'); $auth0 = new Auth0Connect($domain, $clientid, $clientsecret, JRoute::_('index.php?option=com_auth0&task=auth', true, -1)); try { $accessToken = $auth0->getAccessToken($code); $userInfo = $auth0->getUserInfo($accessToken); if (($jUser = $this->doesUserExists($userInfo)) !== null) { $this->loginAuth0User($jUser); } else { $this->createAuth0User($userInfo); } $app = JFactory::getApplication(); $app->redirect('/'); } catch (Exception $e) { echo $e; exit; } }
function AuthJUser() { if (!class_exists('Auth0Connect')) { require_once JPATH_COMPONENT . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'auth0_connect.php'; } if (!class_exists('Auth0ValidationException')) { require_once JPATH_COMPONENT . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'auth0_validation_exception.php'; } $this->app = JFactory::getApplication('site'); $return = $this->getReturn('state', 'RAW'); if (empty($return)) { $return = $this->getReturn('return', 'BASE64'); } if (empty($return)) { $return = 'index.php?option=com_users&view=profile'; } // Set the return URL in the user state to allow modification by plugins $this->app->setUserState('users.login.form.return', $return); $params = JComponentHelper::getParams('com_auth0'); $clientid = $params->get('clientid'); $clientsecret = $params->get('clientsecret'); $domain = 'https://' . $params->get('domain'); $code = $this->app->input->getVar('code'); $auth0 = new Auth0Connect($domain, $clientid, $clientsecret, JRoute::_('index.php?option=com_auth0&task=auth', true, -1)); try { $accessToken = $auth0->getAccessToken($code); $userInfo = $auth0->getUserInfo($accessToken); if (($jUser = $this->doesUserExists($userInfo)) !== null) { $this->loginAuth0User($jUser); } else { if (($jUser = $this->doesUserExistsUnlinked($userInfo)) !== null) { $this->linkAuth0User($jUser, $userInfo); } else { $this->createAuth0User($userInfo); } } $this->app->setUserState('users.login.form.data', array()); $this->app->redirect(JRoute::_($this->app->getUserState('users.login.form.return'), false)); } catch (Auth0ValidationException $e) { $this->app->enqueueMessage($e->getMessage(), 'warning'); $this->app->redirect(JRoute::_('index.php?option=com_users&view=login', false)); } catch (Exception $e) { $this->app->enqueueMessage(JText::sprintf('COM_AUTH0_GENERIC_ERROR'), 'warning'); $this->app->redirect(JRoute::_('index.php?option=com_users&view=login', false)); } }