public function testShouldReturnTokenInfo()
 {
     $wantedTokens = ['access_token' => '1/abdef1234567890', 'expires_in' => '57', 'token_type' => 'Bearer'];
     $jsonTokens = json_encode($wantedTokens);
     $httpHandler = getHandler([buildResponse(200, [GCECredentials::FLAVOR_HEADER => 'Google']), buildResponse(200, [], Psr7\stream_for($jsonTokens))]);
     $g = new GCECredentials();
     $this->assertEquals($wantedTokens, $g->fetchAuthToken($httpHandler));
 }
Exemple #2
0
/**
 *  Flushes exported status message/or any status message to the chart or the output stream on error
 *  It parses the exported status through parser function parseExportedStatus,
 *  builds proper response string using buildResponse function and flushes the response
 *  string to the output stream and terminates the program.
 *  @param  $status     exported status ( false if failed/error, filename as string if success)
 *          $meta       array containing meta descriptions of the chart like width, height
 *          $msg        custom message to be added as statusMessage
 *
 */
function flushStatus($status, $meta, $msg = '')
{
    die(buildResponse(parseExportedStatus($status, $meta, $msg)));
}
 public function testSuccedsIfNoDefaultFilesButIsOnGCE()
 {
     $wantedTokens = ['access_token' => '1/abdef1234567890', 'expires_in' => '57', 'token_type' => 'Bearer'];
     $jsonTokens = json_encode($wantedTokens);
     // simulate the response from GCE.
     $httpHandler = getHandler([buildResponse(200, [GCECredentials::FLAVOR_HEADER => 'Google']), buildResponse(200, [], Psr7\stream_for($jsonTokens))]);
     $this->assertNotNull(ApplicationDefaultCredentials::getSubscriber('a scope', $httpHandler));
 }
 public function testUpdatesTokenFieldsOnFetchMissingRefreshToken()
 {
     $testConfig = $this->fetchAuthTokenMinimal;
     $testConfig['refresh_token'] = 'a_refresh_token';
     $wanted_updates = ['expires_at' => '1', 'expires_in' => '57', 'issued_at' => '2', 'access_token' => 'an_access_token', 'id_token' => 'an_id_token'];
     $json = json_encode($wanted_updates);
     $httpHandler = getHandler([buildResponse(200, [], Psr7\stream_for($json))]);
     $o = new OAuth2($testConfig);
     $this->assertNull($o->getExpiresAt());
     $this->assertNull($o->getExpiresIn());
     $this->assertNull($o->getIssuedAt());
     $this->assertNull($o->getAccessToken());
     $this->assertNull($o->getIdToken());
     $this->assertEquals('a_refresh_token', $o->getRefreshToken());
     $tokens = $o->fetchAuthToken($httpHandler);
     $this->assertEquals(1, $o->getExpiresAt());
     $this->assertEquals(57, $o->getExpiresIn());
     $this->assertEquals(2, $o->getIssuedAt());
     $this->assertEquals('an_access_token', $o->getAccessToken());
     $this->assertEquals('an_id_token', $o->getIdToken());
     $this->assertEquals('a_refresh_token', $o->getRefreshToken());
 }
 public function testNoOpOnFetchAuthToken()
 {
     $testJson = $this->createTestJson();
     $sa = new ServiceAccountJwtAccessCredentials($testJson);
     $this->assertNotNull($sa);
     $httpHandler = getHandler([buildResponse(200)]);
     $result = $sa->fetchAuthToken($httpHandler);
     // authUri has not been set
     $this->assertNull($result);
 }
 public function testCanFetchCredsOK()
 {
     $testJson = createURCTestJson();
     $testJsonText = json_encode($testJson);
     $scope = ['scope/1', 'scope/2'];
     $httpHandler = getHandler([buildResponse(200, [], Psr7\stream_for($testJsonText))]);
     $sa = new UserRefreshCredentials($scope, $testJson);
     $tokens = $sa->fetchAuthToken($httpHandler);
     $this->assertEquals($testJson, $tokens);
 }