In order to use Facebook OAuth you must register your application at . Example application configuration: php 'components' => [ 'authClientCollection' => [ 'class' => 'yii\authclient\Collection', 'clients' => [ 'facebook' => [ 'class' => 'yii\authclient\clients\Facebook', 'clientId' => 'facebook_client_id', 'clientSecret' => 'facebook_client_secret', ], ], ] ... ]
See also: https://developers.facebook.com/apps
See also: http://developers.facebook.com/docs/reference/api
Since: 2.0
Author: Paul Klimov (klimov.paul@gmail.com)
Inheritance: extends yii\authclient\OAuth2
Beispiel #1
0
 /**
  * @inheritdoc
  */
 protected function normalizeUserAttributes($attributes)
 {
     if (!empty($attributes['birthday'])) {
         list($attributes['birth_day'], $attributes['birth_month'], $attributes['birth_year']) = $this->parseBirthday($attributes['birthday']);
     }
     return parent::normalizeUserAttributes($attributes);
 }
Beispiel #2
0
 /**
  * @param int $limit
  *
  * @return array
  */
 public function getPosts($limit = 100)
 {
     return $this->parseGetPosts($this->service->api('me/feed', 'GET'), 'data', ['id', 'message'], ['service_id_author' => 'from.id', 'service_id_post' => 'id', 'time_created' => 'created_time', 'content' => 'message']);
 }
 public function actionAuthClient()
 {
     $model = new SettingsForm();
     $model->googleClientId = Yii::$app->config->get(Enum::GOOGLE_CLIENT_ID);
     $model->googleClientSecret = Yii::$app->config->get(Enum::GOOGLE_CLIENT_SECRET);
     $model->facebookClientId = Yii::$app->config->get(Enum::FACEBOOK_CLIENT_ID);
     $model->facebookClientSecret = Yii::$app->config->get(Enum::FACEBOOK_CLIENT_SECRET);
     $model->linkedInClientId = Yii::$app->config->get(Enum::LINKED_IN_CLIENT_ID);
     $model->linkedInClientSecret = Yii::$app->config->get(Enum::LINKED_IN_CLIENT_SECRET);
     $model->githubClientId = Yii::$app->config->get(Enum::GITHUB_CLIENT_ID);
     $model->githubClientSecret = Yii::$app->config->get(Enum::GITHUB_CLIENT_SECRET);
     $model->liveClientId = Yii::$app->config->get(Enum::LIVE_CLIENT_ID);
     $model->liveClientSecret = Yii::$app->config->get(Enum::LIVE_CLIENT_SECRET);
     $model->twitterConsumerKey = Yii::$app->config->get(Enum::TWITTER_CONSUMER_KEY);
     $model->twitterConsumerSecret = Yii::$app->config->get(Enum::TWITTER_CONSUMER_SECRET);
     $config = Configuration::get();
     if ($model->load(Yii::$app->request->post())) {
         Yii::$app->config->set(Enum::GOOGLE_CLIENT_ID, $model->googleClientId);
         Yii::$app->config->set(Enum::GOOGLE_CLIENT_SECRET, $model->googleClientSecret);
         Yii::$app->config->set(Enum::FACEBOOK_CLIENT_ID, $model->facebookClientId);
         Yii::$app->config->set(Enum::FACEBOOK_CLIENT_SECRET, $model->facebookClientSecret);
         Yii::$app->config->set(Enum::LINKED_IN_CLIENT_ID, $model->linkedInClientId);
         Yii::$app->config->set(Enum::LINKED_IN_CLIENT_SECRET, $model->linkedInClientSecret);
         Yii::$app->config->set(Enum::GITHUB_CLIENT_ID, $model->githubClientId);
         Yii::$app->config->set(Enum::GITHUB_CLIENT_SECRET, $model->githubClientSecret);
         Yii::$app->config->set(Enum::LIVE_CLIENT_ID, $model->liveClientId);
         Yii::$app->config->set(Enum::LIVE_CLIENT_SECRET, $model->liveClientSecret);
         Yii::$app->config->set(Enum::TWITTER_CONSUMER_KEY, $model->twitterConsumerKey);
         Yii::$app->config->set(Enum::TWITTER_CONSUMER_SECRET, $model->twitterConsumerSecret);
         $config['components']['authClientCollection']['class'] = Collection::className();
         if (!empty($model->googleClientId) && !empty($model->googleClientSecret)) {
             Yii::$app->config->set(Enum::GOOGLE_AUTH, GoogleOAuth::className());
             Yii::$app->config->set(Enum::GOOGLE_CLIENT_ID, $model->googleClientId);
             Yii::$app->config->set(Enum::GOOGLE_CLIENT_SECRET, $model->googleClientSecret);
             $config['components']['authClientCollection']['clients']['google']['class'] = GoogleOAuth::className();
             $config['components']['authClientCollection']['clients']['google']['clientId'] = $model->googleClientId;
             $config['components']['authClientCollection']['clients']['google']['clientSecret'] = $model->googleClientSecret;
         } else {
             Yii::$app->config->set(Enum::GOOGLE_AUTH, NULL);
             unset($config['components']['authClientCollection']['clients']['google']);
         }
         if (!empty($model->facebookClientId) && !empty($model->facebookClientSecret)) {
             Yii::$app->config->set(Enum::FACEBOOK_AUTH, Facebook::className());
             Yii::$app->config->set(Enum::FACEBOOK_CLIENT_ID, $model->facebookClientId);
             Yii::$app->config->set(Enum::FACEBOOK_CLIENT_SECRET, $model->facebookClientSecret);
             $config['components']['authClientCollection']['clients']['facebook']['class'] = Facebook::className();
             $config['components']['authClientCollection']['clients']['facebook']['clientId'] = $model->facebookClientId;
             $config['components']['authClientCollection']['clients']['facebook']['clientSecret'] = $model->facebookClientSecret;
         } else {
             Yii::$app->config->set(Enum::FACEBOOK_AUTH, NULL);
             unset($config['components']['authClientCollection']['clients']['facebook']);
         }
         if (!empty($model->linkedInClientId) && !empty($model->linkedInClientSecret)) {
             Yii::$app->config->set(Enum::LINKED_IN_AUTH, LinkedIn::className());
             Yii::$app->config->set(Enum::LINKED_IN_CLIENT_ID, $model->linkedInClientId);
             Yii::$app->config->set(Enum::LINKED_IN_CLIENT_SECRET, $model->linkedInClientSecret);
             $config['components']['authClientCollection']['clients']['linkedin']['class'] = LinkedIn::className();
             $config['components']['authClientCollection']['clients']['linkedin']['clientId'] = $model->linkedInClientId;
             $config['components']['authClientCollection']['clients']['linkedin']['clientSecret'] = $model->linkedInClientSecret;
         } else {
             Yii::$app->config->set(Enum::LINKED_IN_AUTH, NULL);
             unset($config['components']['authClientCollection']['clients']['linkedin']);
         }
         if (!empty($model->githubClientId) && !empty($model->githubClientSecret)) {
             Yii::$app->config->set(Enum::GITHUB_AUTH, GitHub::className());
             Yii::$app->config->set(Enum::GITHUB_CLIENT_ID, $model->githubClientId);
             Yii::$app->config->set(Enum::GITHUB_CLIENT_SECRET, $model->githubClientSecret);
             $config['components']['authClientCollection']['clients']['github']['class'] = GitHub::className();
             $config['components']['authClientCollection']['clients']['github']['clientId'] = $model->githubClientId;
             $config['components']['authClientCollection']['clients']['github']['clientSecret'] = $model->githubClientSecret;
         } else {
             Yii::$app->config->set(Enum::GITHUB_AUTH, NULL);
             unset($config['components']['authClientCollection']['clients']['github']);
         }
         if (!empty($model->liveClientId) && !empty($model->liveClientSecret)) {
             Yii::$app->config->set(Enum::LIVE_AUTH, Live::className());
             Yii::$app->config->set(Enum::LIVE_CLIENT_ID, $model->liveClientId);
             Yii::$app->config->set(Enum::LIVE_CLIENT_SECRET, $model->liveClientSecret);
             $config['components']['authClientCollection']['clients']['live']['class'] = Live::className();
             $config['components']['authClientCollection']['clients']['live']['clientId'] = $model->liveClientId;
             $config['components']['authClientCollection']['clients']['live']['clientSecret'] = $model->liveClientSecret;
         } else {
             Yii::$app->config->set(Enum::LIVE_AUTH, NULL);
             unset($config['components']['authClientCollection']['clients']['live']);
         }
         if (!empty($model->twitterConsumerKey) && !empty($model->twitterConsumerSecret)) {
             Yii::$app->config->set(Enum::TWITTER_AUTH, Twitter::className());
             Yii::$app->config->set(Enum::TWITTER_CONSUMER_KEY, $model->twitterConsumerKey);
             Yii::$app->config->set(Enum::TWITTER_CONSUMER_SECRET, $model->twitterConsumerSecret);
             $config['components']['authClientCollection']['clients']['twitter']['class'] = Twitter::className();
             $config['components']['authClientCollection']['clients']['twitter']['consumerKey'] = $model->twitterConsumerKey;
             $config['components']['authClientCollection']['clients']['twitter']['consumerSecret'] = $model->twitterConsumerSecret;
         } else {
             Yii::$app->config->set(Enum::TWITTER_AUTH, NULL);
             unset($config['components']['authClientCollection']['clients']['twitter']);
         }
         Configuration::set($config);
         Yii::$app->getSession()->setFlash('success', Yii::t('user', 'User module settings saved successfully'));
     }
     return $this->render('authClient', ['model' => $model]);
 }