It supports OpenId, OAuth1 and OAuth2 client types. Usage: php class SiteController extends Controller { public function actions() { return [ 'auth' => [ 'class' => 'yii\authclient\AuthAction', 'successCallback' => [$this, 'successCallback'], ], ] } public function successCallback($client) { $attributes = $client->getUserAttributes(); user login or signup comes here } } Usually authentication via external services is performed inside the popup window. This action handles the redirection and closing of popup window correctly.
See also: Collection
See also: yii\authclient\widgets\AuthChoice
Since: 2.0
Author: Paul Klimov (klimov.paul@gmail.com)
Inheritance: extends yii\base\Action
Exemplo n.º 1
0
 /**
  * Runs the action.
  */
 public function run()
 {
     try {
         return parent::run();
     } catch (Exception $ex) {
         Yii::$app->session->setFlash('error', $ex->getMessage());
         //Yii::$app->session->setFlash('error', Yii::t('yee/auth', "Authentication error occured."));
         return $this->redirectCancel();
     }
 }
Exemplo n.º 2
0
 /** @inheritdoc */
 protected function authSuccess($client)
 {
     if (!is_callable($this->successCallback)) {
         $this->successCallback = [$this, 'onAuthSuccess'];
         parent::authSuccess($client);
     } else {
         /** @var OAuth2 $client */
         $this->onAuthSuccess($client);
         parent::authSuccess($client);
     }
 }
Exemplo n.º 3
0
 /**
  * @inheritdoc
  */
 public function actions()
 {
     $actions = [];
     if ($this->getConfig('socialSettings', 'enabled', false)) {
         $actions['auth'] = ['class' => AuthAction::classname(), 'successCallback' => [$this, 'onAuthSuccess']];
     }
     $captcha = $this->getConfig('registrationSettings', 'captcha', false);
     if ($captcha !== false) {
         $captcha = ArrayHelper::getValue($captcha, 'action', []);
         $actions['captcha'] = $captcha;
     }
     return $actions;
 }
Exemplo n.º 4
0
 /**
  * @inheritdoc
  */
 public function run()
 {
     try {
         return parent::run();
     } catch (\yii\authclient\InvalidResponseException $e) {
         Yii::$app->session->setFlash('warning', Yii::t('app', 'Invalid response got: {response}. Please try again.', ['response' => $e->getMessage()]));
         $this->controller->layout = $this->controller->module->postRegistrationLayout;
         return $this->controller->render($this->errorView);
     } catch (\Exception $e) {
         Yii::$app->session->setFlash('error', Yii::t('app', $e->getMessage()));
         $this->controller->layout = $this->controller->module->postRegistrationLayout;
         return $this->controller->render($this->errorView);
     }
 }
Exemplo n.º 5
0
 protected function authSuccess($client)
 {
     /** @var \yii\authclient\BaseClient $client */
     $this->socialServiceId = SocialService::classNameToId($client->className());
     if ($this->socialServiceId === 0) {
         throw new ServerErrorHttpException("SocialService unknown");
     }
     // first find user service on this id
     $userAttributes = $client->getUserAttributes();
     $this->serviceId = $userAttributes['id'];
     //! @todo Add caching here based on commonTag
     $this->userService = UserService::find()->where(['service_id' => $this->serviceId, 'social_service_id' => $this->socialServiceId])->one();
     return parent::authSuccess($client);
 }
 /** @inheritdoc */
 public function actions()
 {
     return ['auth' => ['class' => AuthAction::className(), 'successCallback' => Yii::$app->user->isGuest ? [$this, 'authenticate'] : [$this, 'connect']]];
 }
Exemplo n.º 7
0
 /**
  * @inheritdoc
  */
 public function getCancelUrl()
 {
     return $this->_module->getSocialSetting('defaultCancelUrl', $this->userType, parent::getCancelUrl());
 }
Exemplo n.º 8
0
 /**
  * @inheritdoc
  */
 public function actions()
 {
     return ['captcha' => ArrayHelper::merge(['class' => $this->module->getClassName(Module::CLASS_CAPTCHA_ACTION)], $this->module->captchaConfig), 'client' => ['class' => AuthAction::className(), 'successCallback' => [$this, 'clientLogin']]];
 }
Exemplo n.º 9
0
 public function actions()
 {
     return ['social' => ['class' => AuthAction::className(), 'successCallback' => [$this, 'social']]];
 }
Exemplo n.º 10
0
 public function actions()
 {
     return ['auth' => ['class' => AuthAction::className(), 'successCallback' => [$this, 'onAuthSuccess']]];
 }
Exemplo n.º 11
0
 /**
  * @inheritdoc
  */
 public function authSuccess($client)
 {
     return parent::authSuccess($client);
 }
 /**
  * @inheritdoc
  */
 public function actions()
 {
     return ['auth' => ['class' => AuthAction::className(), 'successCallback' => [$this, 'authCallback'], 'successUrl' => Yii::$app->urlManager->createAbsoluteUrl(['/user/default/login'])]];
 }