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); }
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; }
/** * @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 static function get(array $options = array()) { return Client::getInstance()->getTenant($options); }
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); }
public function testClientInstanceDefaultsCacheIfNoCacheItemsAreSet() { \Stormpath\Client::tearDown(); $client = \Stormpath\Client::getInstance(); $this->assertInstanceOf('Stormpath\\Cache\\ArrayCacheManager', $client->getCacheManager()); }
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; }
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 function testClient() { self::$client = \Stormpath\Client::getInstance(); $this->assertInstanceOf('Stormpath\\Client', self::$client); }