示例#1
0
 /**
  * @param Session $session
  */
 public function refresh(Session $session)
 {
     if (!is_null($session->getRefreshToken())) {
         $ips = $this->getClientIps();
         $response = $this->request('POST', '/oauth2/auth', null, ['form_params' => ['grant_type' => 'refresh_token', 'client_id' => $this->client_id, 'client_secret' => $this->client_secret, 'refresh_token' => $session->getRefreshToken(), 'ip' => empty($ips) ? null : implode(', ', $ips)]]);
     } else {
         $response = $this->request('POST', '/oauth2/auth', null, ['form_params' => ['grant_type' => 'client_credentials', 'client_id' => $this->client_id, 'client_secret' => $this->client_secret]]);
     }
     $session->set($response);
 }
示例#2
0
 /**
  * @covers Classy\Client::refresh
  */
 public function testRefreshAppToken()
 {
     $session = new Session(['access_token' => '12345', 'expires_in' => -100]);
     $this->assertTrue($session->expired());
     $this->guzzleMock->shouldReceive('request')->once()->with('POST', '/oauth2/auth', Mockery::on(function ($args) {
         return $args['form_params'] === ['grant_type' => 'client_credentials', 'client_id' => '123', 'client_secret' => '456'];
     }))->andReturn(new Response(200, [], json_encode(["access_token" => '56789', "expires_in" => 3600])));
     $this->client->refresh($session);
     $this->assertEquals('56789', $session->getAccessToken());
     $this->assertFalse($session->expired());
 }