public function testCanRefreshAccessToken() { $client = new OAuth2Client(self::$api_key, self::$key_secret, Request::request(self::$endpoint)); $res = $client->getAccessToken()->run(); $this->assertTrue(isset($res['body']['access_token'])); $this->assertTrue(isset($res['body']['refresh_token'])); $this->assertTrue(isset($res['body']['expires_in'])); $res = $client->refreshAccessToken($res['body']['refresh_token'])->run(); $this->assertTrue(isset($res['body']['access_token'])); $this->assertTrue(isset($res['body']['refresh_token'])); $this->assertTrue(isset($res['body']['expires_in'])); }
public function testSetSubPath() { $request = Request::request(self::$endpoint)->path('/foo'); $this->assertEquals($request->subpath('/bar')->find('PATH'), '/foo/bar'); }
public static function build_session_client() { $req = Request::request(self::$endpoint); $client = new OAuth2Client(self::$api_key, self::$key_secret, $req); $authenticator = new Authenticator($client); $post = $req->auth($authenticator)->post()->json(); // Create a user $user = $post->path('/users')->body(Examples::user())->run()['body']; // Create a team. $team = $post->path('/users/' . $user['userId'] . '/teams')->body(Examples::team())->run()['body']; // Create an api client for that team owned by that user. $client = $post->path('/system/clients')->body(Examples::client($user['userId'], $team['teamId']))->run()['body']; return $client; }
public function testDeferedAuth() { $called = 0; // #yolophp $mkAuth = function () use(&$called) { $called++; return 'Bearer token'; }; $request = Request::request(self::$endpoint); $res = $request->auth($mkAuth)->run(); $this->assertTrue($res['ok']); $this->assertEquals($res['body']['headers']['authorization'], 'Bearer token'); $this->assertEquals($called, 1); }