Example #1
0
 /**
  * Takes an identity provider access token and fetches the user data from that provider.
  * A new User object is created if that user doesn't exist.
  * Access tokens are returned upon successful authentication using one of the SDKs from
  * Facebook, Google, Twitter, etc.
  * <b>Note:</b> Twitter uses OAuth 1 and gives you a token and a token secret.
  * <b>You must concatenate them like this: <code>{oauth_token}:{oauth_token_secret}</code> and
  * use that as the provider access token.</b>
  * @param $provider identity provider, e.g. 'facebook', 'google'...
  * @param $providerToken access token from a provider like Facebook, Google, Twitter
  * @return ParaObject|null a User object or null if something failed
  */
 public function signIn($provider, $providerToken)
 {
     if ($provider != null && $providerToken != null) {
         $credentials = array();
         $credentials["appid"] = $this->accessKey;
         $credentials["provider"] = $provider;
         $credentials["token"] = $providerToken;
         $result = $this->getEntity($this->invokePost(self::JWT_PATH, $credentials));
         if ($result != null && array_key_exists("user", $result) && array_key_exists("jwt", $result)) {
             $jwtData = $result["jwt"];
             $userData = $result["user"];
             $this->tokenKey = $jwtData["access_token"];
             $this->tokenKeyExpires = $jwtData["expires"];
             $this->tokenKeyNextRefresh = $jwtData["refresh"];
             $obj = new ParaObject();
             $obj->setFields($userData);
             return $obj;
         } else {
             $this->clearAccessToken();
         }
     }
     return null;
 }