'state' => $authState, ]; return $this->composeUrl($this->authUrl, array_merge($defaultParams, $params)); } protected function signPKCS7($message) { if (! file_exists($this->certPath)) { throw new Exception('Could not open Cert file'); } if (! file_exists($this->privateKeyPath)) { throw new Exception('Could not open Key file'); } $certContent = file_get_contents($this->certPath); $keyContent = file_get_contents($this->privateKeyPath); $cert = openssl_x509_read($certContent);
public function buildAuthUrl(array $params = []) { $timestamp = date("Y.m.d H:i:s O"); $authState = $this->generateAuthState(); $this->setState('authState', $authState); $clientSecret = $this->scope . $timestamp . $this->clientId . $authState; $clientSecret = $this->signPKCS7($clientSecret); if ($clientSecret === false) { throw new Exception('signPKCS7 error'); } $defaultParams = [
if (!empty($token)) { return $this->authSuccess($client); } return $this->authCancel($client); } $url = $client->buildAuthUrl($authUrlParams); return Yii::$app->getResponse()->redirect($url); } }
* @return Response response instance. * @throws \yii\base\NotSupportedException on invalid client. */ protected function auth($client, $authUrlParams = []) { if ($client instanceof OAuth2) { return $this->authOAuth2($client, $authUrlParams); } elseif ($client instanceof OAuth1) { return $this->authOAuth1($client, $authUrlParams); } elseif ($client instanceof OpenId) { return $this->authOpenId($client); }
$collection = Yii::$app->get($this->clientCollection); if (!$collection->hasClient($clientId)) { throw new NotFoundHttpException("Unknown auth client '{$clientId}'"); } $client = $collection->getClient($clientId); return $this->auth($client); } throw new NotFoundHttpException(); } /**
$args = $this->controller->bindActionParams($this, $params); Yii::debug('Running action: ' . get_class($this) . '::run(), invoked by ' . get_class($this->controller), __METHOD__); if (Yii::$app->requestedParams === null) { Yii::$app->requestedParams = $args; } if ($this->beforeRun()) { $result = call_user_func_array([$this, 'run'], $args); $this->afterRun(); return $result; } return null;
} $result = null; if ($runAction && $this->beforeAction($action)) { // run the action $result = $action->runWithParams($params); $result = $this->afterAction($action, $result); // call afterAction on modules foreach ($modules as $module) { /* @var $module Module */
$parts = $this->createController($route); if (is_array($parts)) { /* @var $controller Controller */ list($controller, $actionID) = $parts; $oldController = Yii::$app->controller; Yii::$app->controller = $controller; $result = $controller->runAction($actionID, $params); if ($oldController !== null) { Yii::$app->controller = $oldController; } return $result; }
$params = $this->catchAll; unset($params[0]); } try { Yii::debug("Route requested: '$route'", __METHOD__); $this->requestedRoute = $route; $result = $this->runAction($route, $params); if ($result instanceof Response) { return $result; } $response = $this->getResponse(); if ($result !== null) {
{ try { $this->state = self::STATE_BEFORE_REQUEST; $this->trigger(self::EVENT_BEFORE_REQUEST); $this->state = self::STATE_HANDLING_REQUEST; $response = $this->handleRequest($this->getRequest()); $this->state = self::STATE_AFTER_REQUEST; $this->trigger(self::EVENT_AFTER_REQUEST); $this->state = self::STATE_SENDING_RESPONSE; $response->send();
require(__DIR__ . '/../vendor/autoload.php'); require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php'); $config = require(__DIR__ . '/../config/web.php'); (new yii\web\Application($config))->run();
$_GET = [ 'r' => 'site/auth', 'authclient' => 'esia', ]; $_SESSION = [ '__flash' => [], 'heggi\\yii2esia\\Esia_esia_authState' => '5bc9a52a-8d58-42da-a9ff-5705e23768b8', ];