示例#1
0
 /**
  * Check simpliest fromArray and token
  */
 public function testTokenFromArray()
 {
     $json = '{"accessToken":"590ec8e107fd345c328e258e0dd12dda","expiresIn":3600,"refreshToken":"7e8bdae569e94caa89a60a9825b0a302"}';
     $token = new Token();
     $token->fromArray(json_decode($json, true));
     $token->validate();
     $this->assertEquals('590ec8e107fd345c328e258e0dd12dda', $token->getAccessToken());
     $this->assertEquals('7e8bdae569e94caa89a60a9825b0a302', $token->getRefreshToken());
     $this->assertEquals(3600, $token->getExpiresIn());
 }
示例#2
0
 public function getToken()
 {
     if (!$this->token || $this->token->getExpiresIn() + $this->tokenFetchTime < time()) {
         //fetch new token. Do not refresh (yet) since PHP follows request-reponse model and does not have any
         //persistent storage by default
         if (!$this->username || !$this->password) {
             throw new CoinfideException('Please call "setCredentials" and provide your credentials');
         }
         $response = $this->request('auth/token', array('username' => $this->username, 'password' => $this->password));
         $token = new Token();
         $token->fromArray($response);
         return $this->token = $token;
     }
     return $this->token;
 }