/** * @test */ public function testConstruction() { $authToken = AuthToken::loadJson('{"access":{"token":{"expires": "2012-09-14T15:11:57.585-05:00","id": "858fb4c2-bf15-4dac-917d-8ec750ae9baa","tenant": {"id": "010101","name": "0101012"}}}}'); $this->checkToken($authToken); $d = $authToken->getAuthDocument(); $authToken = new AuthToken(); $authToken->setExpires(new \DateTime('2012-09-14T15:11:57.585-05:00'))->setId('858fb4c2-bf15-4dac-917d-8ec750ae9baa')->setTenantId('010101')->setTenantName('0101012')->setAuthDocument($d)->setRegionEndpoints(array())->setZones(array()); $this->checkToken($authToken); unset($authToken); unset($authToken); }
/** * Performs an authentication request * * @return object Returns result */ public function auth() { $cfg = $this->getConfig(); $options = ['auth' => $cfg->getAuthQueryString()]; $response = $this->call($cfg->getIdentityEndpoint(), '/tokens', $options, 'POST', null, false); if ($response->hasError() === false) { $str = $response->getContent(); $result = json_decode($str); $cfg->setAuthToken(AuthToken::loadJson($str)); //Trying to fetch stage keystone $regionEndpoints = $cfg->getAuthToken()->getRegionEndpoints(); /* if (isset($regionEndpoints['identity'][$cfg->getRegion()][''][0]->publicURL)) { $regionKeystoneURL = $regionEndpoints['identity'][$cfg->getRegion()][''][0]->publicURL; if ($cfg->getIdentityEndpoint() != $regionKeystoneURL) { $response = $this->call($regionKeystoneURL, '/tokens', $options, 'POST', null, false); if ($response->hasError() === false) { $str = $response->getContent(); $result = json_decode($str); //Sets original auth token for current region $cfg->setAuthToken(AuthToken::loadJson($str)); $cfg->setIdentityEndpoint($regionKeystoneURL); } } } */ } return $result; }
/** * Performs an authentication request * * @return object Returns result */ public function auth() { $cfg = $this->getConfig(); $options = array('auth' => $cfg->getAuthQueryString()); $response = $this->call($cfg->getIdentityEndpoint(), '/tokens', $options, 'POST', null, false); if ($response->hasError() === false) { $str = $response->getContent(); $result = json_decode($str); $cfg->setAuthToken(AuthToken::loadJson($str)); if (($cb = $cfg->getUpdateTokenCallback()) !== null && is_callable($cb)) { //It should save token in database $cb($cfg->getAuthToken()); } } return $result; }