protected function _init() { $app = App::i(); $config = array_merge(['timeout' => '24 hours', 'salt' => 'LT_SECURITY_SALT_SECURITY_SALT_SECURITY_SALT_SECURITY_SALT_SECU', 'login_url' => 'https://www.google.com/accounts/o8/id', 'path' => preg_replace('#^https?\\:\\/\\/[^\\/]*(/.*)#', '$1', $app->createUrl('auth'))], $this->_config); $opauth_config = ['Strategy' => ['OpenID' => ['identifier_form' => THEMES_PATH . 'active/views/auth-form.php', 'url' => $config['login_url']]], 'security_salt' => $config['salt'], 'security_timeout' => $config['timeout'], 'path' => $config['path'], 'callback_url' => $app->createUrl('auth', 'response')]; $opauth = new \Opauth($opauth_config, false); $this->opauth = $opauth; if ($config['logout_url']) { $app->hook('auth.logout:after', function () use($app, $config) { $app->redirect($config['logout_url'] . '?next=' . $app->baseUrl); }); } // add actions to auth controller $app->hook('GET(auth.index)', function () use($app) { $app->redirect($this->createUrl('openid')); }); $app->hook('<<GET|POST>>(auth.openid)', function () use($opauth, $config) { $_POST['openid_url'] = $config['login_url']; $opauth->run(); }); $app->hook('GET(auth.response)', function () use($app) { $app->auth->processResponse(); if ($app->auth->isUserAuthenticated()) { $app->redirect($app->auth->getRedirectPath()); } else { if ($app->config['app.mode'] === 'production') { $app->redirect($this->createUrl('error')); } else { echo '<pre>'; var_dump($this->data, $_POST, $_GET, $_REQUEST, $_SESSION); die; } } }); }
protected function _init() { $app = App::i(); $url = $app->createUrl('auth'); $config = array_merge(['timeout' => '24 hours', 'salt' => 'LT_SECURITY_SALT_SECURITY_SALT_SECURITY_SALT_SECURITY_SALT_SECU', 'client_secret' => '', 'cliente_id' => '', 'path' => preg_replace('#^https?\\:\\/\\/[^\\/]*(/.*)#', '$1', $url)], $this->_config); $opauth_config = ['strategy_dir' => PROTECTED_PATH . '/vendor/opauth/', 'Strategy' => ['logincidadao' => $config], 'security_salt' => $config['salt'], 'security_timeout' => $config['timeout'], 'host' => preg_replace('#^(https?\\:\\/\\/[^\\/]*)/.*#', '$1', $url), 'path' => $config['path'], 'callback_url' => $app->createUrl('auth', 'response')]; if (isset($config['onCreateRedirectUrl'])) { $this->onCreateRedirectUrl = $config['onCreateRedirectUrl']; } $opauth = new \Opauth($opauth_config, false); $this->opauth = $opauth; // add actions to auth controller $app->hook('GET(auth.index)', function () use($app) { $app->redirect($this->createUrl('logincidadao')); }); $app->hook('<<GET|POST>>(auth.logincidadao)', function () use($opauth, $config) { // $_POST['openid_url'] = $config['login_url']; $opauth->run(); }); $app->hook('GET(auth.response)', function () use($app) { $app->auth->processResponse(); if ($app->auth->isUserAuthenticated()) { $app->redirect($app->auth->getRedirectPath()); } else { $app->redirect($this->createUrl('')); } }); }
/** * @return LoginProviderEntity * @throws \Nette\InvalidStateException * @throws \Nette\InvalidArgumentException */ protected function createLoginProviderEntity() { $type = $this->getOpauthType(); $params = array('path' => $this->getCallbackUrl(), 'callback_url' => $this->getCallbackUrl(), 'Strategy' => array($type => $this->getConfig())); Debugger::$maxLen = 10000; $this->opauth = new Opauth($params, FALSE); $this->opauth->strategy = Strings::lower($type); $response = null; switch ($this->opauth->env['callback_transport']) { case 'session': $response = $_SESSION['opauth']; unset($_SESSION['opauth']); break; case 'post': $response = unserialize(base64_decode($_POST['opauth'])); break; case 'get': $response = unserialize(base64_decode($_GET['opauth'])); break; default: throw new InvalidArgumentException("Unsupported callback transport."); break; } if ($response === NULL) { if (isset($_GET['_opauth_action'])) { $action = explode('/', $_GET['_opauth_action']); $this->opauth->action = $action[1]; } $this->opauth->run(); } if (array_key_exists('error', $response)) { throw new InvalidStateException($response['error']['message']); } if (empty($response['auth']) || empty($response['timestamp']) || empty($response['signature']) || empty($response['auth']['provider']) || empty($response['auth']['uid'])) { throw new InvalidStateException('Invalid auth response: Missing key auth response components'); } elseif (!$this->opauth->validate(sha1(print_r($response['auth'], true)), $response['timestamp'], $response['signature'], $reason)) { throw new InvalidStateException('Invalid auth response: ' . $reason); } $ret = new LoginProviderEntity($response['auth']['uid'], static::getType()); $this->fillLoginEntity($ret, $response['auth']['raw']); return $ret; }
/** * Assign opauth expected route params then run. */ public function run() { $this->env['params'][0] = Request::$current->param('strategy'); $this->env['params'][1] = Request::$current->param('callback'); parent::run(); }