示例#1
0
 /**
  * this method is called through King23s routing,
  * it is supposed to offer a list of OAuth2 Providers
  * which the user can use to authenticate himself
  * @param array $params
  * returns string
  */
 public function login(array $params)
 {
     $reg = \King23\Core\Registry::getInstance();
     $state = \Kingboard\Lib\Form::getXSRFToken();
     $list = array();
     foreach ($reg->oAuth2ProviderList as $provider => $config) {
         $class = $config['auth_class'];
         $list[$provider] = \Kingboard\Lib\Auth\OAuth2\Consumer::getCodeRedirect($class::getCodeUrl(), $config["client_id"], $config["redirect_url"], $state, $class::getScope());
     }
     return $this->render("user/oauth.html", array("providerlist" => $list));
 }
示例#2
0
 /**
  * execute the login
  * @static
  * @param array $config this providers config array from the registry
  * @return \Kingboard\Model\User
  */
 public static function login($config, $fake)
 {
     if (isset($_GET['error'])) {
         throw new \Exception("Could not login: "******"Error: could not access tokens");
     }
     $userinfo = json_decode(file_get_contents("https://graph.facebook.com/me?access_token=" . $tokens['access_token']));
     if (is_null($userinfo)) {
         throw new \Exception("Error: could not access userinfo");
     }
     $user = \Kingboard\Model\User::findOne(array("username" => $userinfo->email));
     if (is_null($user)) {
         $user = new \Kingboard\Model\User();
         $user->username = $userinfo->email;
         $user->save();
     }
     $_SESSION["Kingboard_Auth"] = array("User" => $user);
     return $user;
 }