public static function setUpBeforeClass() { if (self::$client) { return; } $apiKeyProperties = null; $apiKeyFileLocation = null; if (array_key_exists(self::STORMPATH_SDK_TEST_API_KEY_FILE_LOCATION, $_SERVER) or array_key_exists(self::STORMPATH_SDK_TEST_API_KEY_FILE_LOCATION, $_ENV)) { $apiKeyFileLocation = array_key_exists(self::STORMPATH_SDK_TEST_API_KEY_FILE_LOCATION, $_SERVER) ? $_SERVER[self::STORMPATH_SDK_TEST_API_KEY_FILE_LOCATION] : $_ENV[self::STORMPATH_SDK_TEST_API_KEY_FILE_LOCATION]; } elseif ((array_key_exists(self::STORMPATH_SDK_TEST_API_KEY_ID, $_SERVER) or array_key_exists(self::STORMPATH_SDK_TEST_API_KEY_ID, $_ENV)) and (array_key_exists(self::STORMPATH_SDK_TEST_API_KEY_SECRET, $_SERVER) or array_key_exists(self::STORMPATH_SDK_TEST_API_KEY_SECRET, $_ENV))) { $apiKeyId = array_key_exists(self::STORMPATH_SDK_TEST_API_KEY_ID, $_SERVER) ? $_SERVER[self::STORMPATH_SDK_TEST_API_KEY_ID] : $_ENV[self::STORMPATH_SDK_TEST_API_KEY_ID]; $apiKeySecret = array_key_exists(self::STORMPATH_SDK_TEST_API_KEY_SECRET, $_SERVER) ? $_SERVER[self::STORMPATH_SDK_TEST_API_KEY_SECRET] : $_ENV[self::STORMPATH_SDK_TEST_API_KEY_SECRET]; $apiKeyProperties = "apiKey.id={$apiKeyId}\napiKey.secret={$apiKeySecret}"; } else { $message = "The '" . self::STORMPATH_SDK_TEST_API_KEY_FILE_LOCATION . "' environment variable needs to be set before running the tests.\n" . "Alternatively, you can set the '" . self::STORMPATH_SDK_TEST_API_KEY_ID . "' and '" . self::STORMPATH_SDK_TEST_API_KEY_SECRET . "' environment " . "variables to make the tests run."; throw new \InvalidArgumentException($message); } $baseUrl = ''; if (array_key_exists(self::BASE_URL, $_SERVER) or array_key_exists(self::BASE_URL, $_ENV)) { $baseUrl = $_SERVER[self::BASE_URL] ?: $_ENV[self::BASE_URL]; } \Stormpath\Client::$apiKeyFileLocation = $apiKeyFileLocation; \Stormpath\Client::$apiKeyProperties = $apiKeyProperties; \Stormpath\Client::$baseUrl = $baseUrl; \Stormpath\Client::$cacheManager = 'Array'; self::$client = \Stormpath\Client::getInstance(); }
public static function create($properties, array $options = array()) { $groupMembership = $properties; if (!$groupMembership instanceof GroupMembership) { $groupMembership = self::instantiate($properties); } return self::_create($groupMembership->getAccount(), $groupMembership->getGroup(), Client::getInstance()->getDataStore(), $options); }
public static function create($properties, array $options = array()) { $directory = $properties; if (!$directory instanceof Directory) { $directory = self::instantiate($properties); } return Client::create('/' . self::PATH, $directory, $options); }
public static function create($properties, array $options = array()) { $application = $properties; if (!$application instanceof Application) { $application = self::instantiate($properties); } return Client::create('/' . self::PATH, $application, $options); }
private function registerClient() { $id = config('stormpath.client.apiKey.id'); $secret = config('stormpath.client.apiKey.secret'); Client::$apiKeyProperties = "apiKey.id={$id}\napiKey.secret={$secret}"; Client::$integration = self::INTEGRATION_NAME . "/" . self::INTEGRATION_VERSION; $this->app->singleton('stormpath.client', function () { return Client::getInstance(); }); }
/** * Register bindings in the container. * * @return void */ public function register() { $this->app->singleton('stormpath.client', function ($app) { Client::$apiKeyProperties = "apiKey.id=" . config('stormpath.id') . "\napiKey.secret=" . config('stormpath.secret'); Client::$integration = self::INTEGRATION_NAME . "/" . self::INTEGRATION_VERSION; return Client::getInstance(); }); $this->app->singleton('stormpath.application', function ($app) { $application = $app['stormpath.client']->get('applications/' . config('stormpath.application'), STORMPATH::APPLICATION); return $application; }); }
public function testNullCacheDoesNotCache() { $origClient = parent::$client->dataStore->cache; parent::$client->tearDown(); \Stormpath\Client::$cacheManager = 'Null'; $client = \Stormpath\Client::getInstance(); $cache = $client->cacheManager->getCache(); $application = \Stormpath\Resource\Application::create(array('name' => 'Another App for Null Cache ' . md5(time()))); $appInCache = $cache->get($application->href); $this->assertNull($appInCache); $application->delete(); parent::$client = $origClient; }
private function getAuthenticationTokens() { $encodedAuthenticationTokens = $this->getEncodedAuthenticationToken(); $decoded = base64_decode($encodedAuthenticationTokens); $sandv = $this->getSchemeAndValue(); if ($sandv[0] == 'Basic') { $tokens = explode(":", $decoded, 2); } else { if ($sandv[0] == 'Bearer') { $apiSecret = Client::getInstance()->getDataStore()->getApiKey()->getSecret(); $token = JWT::decode($encodedAuthenticationTokens, $apiSecret, array('HS256')); $tokens = array($token->sub, null); } else { throw new \InvalidArgumentException('The Scheme is not valid'); } } if (count($tokens) != 2) { throw new \InvalidArgumentException('It appears the Authorization header is not formatted correctly.'); } return $tokens; }
public function testShouldBeAbleToGetApplicationViaHTMLFragment() { $application = \Stormpath\Resource\Application::create(array('name' => makeUniqueName('ApplicationTest testFragment'))); $href = $application->href; $hrefParts = array_reverse(explode('/', $href)); $app = \Stormpath\Resource\Application::get($hrefParts[0]); $this->assertInstanceOf('\\Stormpath\\Resource\\Application', $app); $this->assertEquals($href, $app->href); $app2 = \Stormpath\Client::get($hrefParts[1] . '/' . $hrefParts[0], Stormpath::APPLICATION); $this->assertInstanceOf('\\Stormpath\\Resource\\Application', $app2); $this->assertEquals($href, $app2->href); $application->delete(); }
public static function tearDownAfterClass() { self::$client = null; Client::tearDown(); }
protected function generateResponseUrl() { $jwt = array(); $jwt['iss'] = 'https://stormpath.com'; $jwt['sub'] = self::$account->href; $jwt['aud'] = UUID::v4(); $jwt['exp'] = time() + 60; $jwt['iat'] = time(); $jwt['jti'] = UUID::v4(); $jwt['irt'] = UUID::v4(); $jwt['state'] = ""; $jwt['isNewSub'] = false; $jwt['status'] = "AUTHENTICATED"; $apiSecret = Client::getInstance()->getDataStore()->getApiKey()->getSecret(); $token = JWT::encode($jwt, $apiSecret); return 'https://stormpath.com?jwtResponse=' . $token; }
/** * @test */ public function it_defaults_to_sauthc1() { $client = \Stormpath\Client::getInstance(); $this->assertInstanceOf('\\Stormpath\\Http\\Authc\\SAuthc1RequestSigner', $client->getDataStore()->getRequestExecutor()->getSigner()); }
/** * @test */ public function it_can_get_the_organization_off_the_data_store() { $org = Client::getInstance()->dataStore->getResource(self::$organization->href, Stormpath::ORGANIZATION); $this->assertEquals(self::$organization->href, $org->href); }
private function registerClient() { $id = config('stormpath.client.apiKey.id'); $secret = config('stormpath.client.apiKey.secret'); Client::$apiKeyProperties = "apiKey.id={$id}\napiKey.secret={$secret}"; Client::$integration = $this->buildAgent(); $this->app->singleton('stormpath.client', function () { return Client::getInstance(); }); }
public static function get($href, array $options = array()) { return Client::get($href, self::class, self::PATH, $options); }
public static function instantiate($properties = null) { return Client::instantiate(Stormpath::LINKEDIN_PROVIDER, $properties); }
/** * @param $href * @param array $options * @return mixed */ public static function get($href, array $options = []) { return Client::get($href, Stormpath::ACCESS_TOKEN, self::PATH, $options); }
private function buildAccessToken($apiKey) { $apiSecret = Client::getInstance()->getDataStore()->getApiKey()->getSecret(); $jwt = JWT::encode(array("sub" => $apiKey->id, "iss" => $this->application->getHref(), "iat" => time(), "exp" => time() + 3600), $apiSecret); return $jwt; }
public function testClientInstanceDefaultsCacheIfNoCacheItemsAreSet() { \Stormpath\Client::tearDown(); $client = \Stormpath\Client::getInstance(); $this->assertInstanceOf('Stormpath\\Cache\\ArrayCacheManager', $client->getCacheManager()); }
public function testShouldBeAbleToGetDirectoryViaHTMLFragment() { $directory = \Stormpath\Resource\Directory::create(array('name' => makeUniqueName('DirectoryTest htmlFragment'))); $href = $directory->href; $hrefParts = array_reverse(explode('/', $href)); $dir = \Stormpath\Resource\Directory::get($hrefParts[0]); $this->assertInstanceOf('\\Stormpath\\Resource\\Directory', $dir); $this->assertEquals($href, $dir->href); $dir2 = \Stormpath\Client::get($hrefParts[1] . '/' . $hrefParts[0], Stormpath::DIRECTORY); $this->assertInstanceOf('\\Stormpath\\Resource\\Directory', $dir2); $this->assertEquals($href, $dir2->href); $directory->delete(); }
public static function get(array $options = array()) { return Client::getInstance()->getTenant($options); }
public function testShouldBeAbleToGetGroupViaHTMLFragment() { $group = \Stormpath\Resource\Group::instantiate(array('name' => makeUniqueName('GroupTest htmlFragment'))); self::$directory->createGroup($group); $href = $group->href; $hrefParts = array_reverse(explode('/', $href)); $group = \Stormpath\Resource\Group::get($hrefParts[0]); $this->assertInstanceOf('\\Stormpath\\Resource\\Group', $group); $this->assertEquals($href, $group->href); $group2 = \Stormpath\Client::get($hrefParts[1] . '/' . $hrefParts[0], Stormpath::GROUP); $this->assertInstanceOf('\\Stormpath\\Resource\\Group', $group2); $this->assertEquals($href, $group2->href); $group->delete(); }
/** * @param $href * @param array $options * @return mixed */ public static function get($href, array $options = array()) { return Client::get($href, Stormpath::OAUTH_POLICY, self::PATH, $options); }
public static function instantiate($properties = null) { return Client::instantiate(Stormpath::ACCOUNT, $properties); }
/** * @expectedException \Stormpath\Resource\ResourceError * @expectedExceptionMessage The imported password designates an algorithm that is an unsupported value. */ public function testImportingInvalidPasswordFormatTypeShouldThrowException() { $username = md5(time() . microtime() . uniqid()) . 'username'; $client = Client::getInstance(); self::$application = \Stormpath\Resource\Application::instantiate(array('name' => 'Main App for passwordImport' . md5(time() . microtime() . uniqid()), 'description' => 'Description of Main App', 'status' => 'enabled')); self::createResource(\Stormpath\Resource\Application::PATH, self::$application, array('createDirectory' => true)); $account = $client->dataStore->instantiate(\Stormpath\Stormpath::ACCOUNT); $account->email = '*****@*****.**'; $account->givenName = 'John'; $account->password = '******'; $account->surname = 'Smith'; $account->username = $username; self::$application->createAccount($account, array('passwordFormat' => 'someOtherMCF')); $result = self::$application->authenticate($username, 'SomePassw0rd!'); $this->assertEquals($username, $result->account->username); $account->delete(); }
public function testClient() { self::$client = \Stormpath\Client::getInstance(); $this->assertInstanceOf('Stormpath\\Client', self::$client); }