public function authenticate(ExchangeIdSiteTokenRequest $exchangeIdSiteTokenRequest) { $attempt = new ExchangeIdSiteTokenAttempt(); $attempt->setGrantType($exchangeIdSiteTokenRequest->getGrantType())->setToken($exchangeIdSiteTokenRequest->getToken()); $grantResult = $this->application->dataStore->create($this->application->getHref() . self::OAUTH_TOKEN_PATH, $attempt, \Stormpath\Stormpath::GRANT_AUTHENTICATION_TOKEN); $builder = new OauthGrantAuthenticationResultBuilder($grantResult); return $builder->build(); }
public static function setUpBeforeClass() { parent::setUpBeforeClass(); self::$application = \Stormpath\Resource\Application::instantiate(array('name' => 'Main App for the tests' . md5(time()), 'description' => 'Description of Main App', 'status' => 'enabled')); parent::createResource(\Stormpath\Resource\Application::PATH, self::$application, array('createDirectory' => true)); self::$account = \Stormpath\Resource\Account::instantiate(array('givenName' => 'PHP', 'middleName' => 'BasicRequestAuthenticator', 'surname' => 'Test', 'username' => md5(time() . microtime() . uniqid()) . 'username', 'email' => md5(time() . microtime() . uniqid()) . '@unknown123.kot', 'password' => 'superP4ss')); self::$application->createAccount(self::$account); }
protected static function init() { self::$application = \Stormpath\Resource\Application::instantiate(array('name' => 'Main App for the tests' . md5(time() . microtime() . uniqid()), 'description' => 'Description of Main App', 'status' => 'enabled')); self::createResource(\Stormpath\Resource\Application::PATH, self::$application, array('createDirectory' => true)); self::$account = \Stormpath\Resource\Account::instantiate(array('givenName' => 'Account Name', 'middleName' => 'Middle Name', 'surname' => 'Surname', 'username' => md5(time() . microtime() . uniqid()) . 'username', 'email' => md5(time() . microtime() . uniqid()) . '@unknown123.kot', 'password' => 'superP4ss')); self::$application->createAccount(self::$account); self::$inited = true; }
public static function setUpBeforeClass() { parent::setUpBeforeClass(); self::$application = \Stormpath\Resource\Application::instantiate(array('name' => makeUniqueName('Application ApiRequestAuthenticatorTest'), 'description' => 'Application for ApiRequestAuthenticatorTest', 'status' => 'enabled')); parent::createResource(\Stormpath\Resource\Application::PATH, self::$application, array('createDirectory' => true)); self::$account = \Stormpath\Resource\Account::instantiate(array('givenName' => 'PHP', 'middleName' => 'ApiRequestAuthenticatorTest', 'surname' => 'Test', 'username' => makeUniqueName('ApiRequestAuthenticatorTest'), 'email' => makeUniqueName('ApiRequestAuthenticatorTest') . '@unknown123.kot', 'password' => 'superP4ss')); self::$application->createAccount(self::$account); self::$apiKey = self::$account->createApiKey(); }
public static function setUpBeforeClass() { parent::setUpBeforeClass(); self::$application = \Stormpath\Resource\Application::instantiate(array('name' => uniqid() . 'ApplicationTest', 'description' => 'Description of Main App', 'status' => 'enabled')); self::createResource(\Stormpath\Resource\Application::PATH, self::$application, array('createDirectory' => true)); self::$account = \Stormpath\Resource\Account::instantiate(array('givenName' => 'Account Name', 'middleName' => 'Middle Name', 'surname' => 'Surname', 'username' => 'username' . uniqid(), 'email' => 'username' . uniqid() . '@unknown123.kot', 'password' => 'superP4ss')); self::$application->createAccount(self::$account); self::$provider = new \Stormpath\StormpathUserProvider(self::$client, self::$application); }
public function verify($jwt = null) { // JWT was not passed in if (!$jwt) { $jwt = $this->retrieveJwtFromHeader(); } // JWT was not in header if (!$jwt) { $jwt = $this->retrieveJwtFromCookie(); } // JWT not in Header or Cookie if (!$jwt) { throw new \InvalidArgumentException('Could not find access token, please pass in JWT'); } if ($this->localValidation) { return JWT::decode($jwt, $this->application->dataStore->getApiKey()->getSecret(), ['HS256']); } $href = $this->application->getHref() . '/authTokens/' . $jwt; return $this->application->dataStore->getResource($href, Stormpath::ACCESS_TOKEN); }
public function addUser() { $result = DB::table('user_table')->insert(['user_id' => $_POST['user_id'], 'user_name' => $_POST['user_name'], 'user_lastname' => $_POST['user_lastname'], 'user_firstname' => $_POST['user_firstname'], 'user_motto' => $_POST['user_motto'], 'email' => $_POST['email'], 'password' => $_POST['password'], 'avatar' => $_POST['avatar'], 'linked_account' => $_POST['linked_account'], 'linked_account_type' => $_POST['linked_account_type'], 'status' => $_POST['status'], 'location' => $_POST['location'], 'background_img' => $_POST['background_img'], 'insert_date' => DB::raw('CURRENT_TIMESTAMP'), 'update_at' => $_POST['update_at']]); //此处前台必须添加限制 $id = $_ENV['STORMPATH_ID']; $secret = $_ENV['STORMPATH_SECRET']; \Stormpath\Client::$apiKeyProperties = "apiKey.id={$id}\napiKey.secret={$secret}"; $application = \Stormpath\Resource\Application::get($_ENV['STORMPATH_APPLICATION']); $account = \Stormpath\Resource\Account::instantiate(array('givenName' => $_POST['user_firstname'], 'surname' => $_POST['user_lastname'], 'email' => $_POST['email'], 'password' => $_POST['password'])); $application->createAccount($account); return response()->json(['result' => $result]); }
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; }
public function testCreateApplication() { $tenant = self::$client->tenant; $application = \Stormpath\Resource\Application::instantiate(array('name' => makeUniqueName('TenantTest CreateApp'))); $tenant->createApplication($application); $this->assertInstanceOf('\\Stormpath\\Resource\\Application', $application); $this->assertEquals($tenant->name, $application->tenant->name); $this->assertContains('CreateApp', $application->name); foreach ($tenant->applications as $app) { $this->assertInstanceOf('\\Stormpath\\Resource\\Application', $app); } $application->delete(); }
public function testCreateApplication() { $tenant = self::$client->tenant; $application = \Stormpath\Resource\Application::instantiate(array('name' => 'App for this test' . md5(time() . microtime() . uniqid()))); $tenant->createApplication($application); $this->assertInstanceOf('\\Stormpath\\Resource\\Application', $application); $this->assertEquals($tenant->name, $application->tenant->name); $this->assertContains('App for this test', $application->name); foreach ($tenant->applications as $app) { $this->assertInstanceOf('\\Stormpath\\Resource\\Application', $app); } $application->delete(); }
private function registerApplication() { $this->app->bind('stormpath.application', function () { if (config('stormpath.application.href') == null) { throw new \InvalidArgumentException('Application href MUST be set.'); } if (!$this->isValidApplicationHref()) { throw new \InvalidArgumentException(config('stormpath.application.href') . ' is not a valid Stormpath Application HREF.'); } $application = \Stormpath\Resource\Application::get(config('stormpath.application.href')); $this->enhanceConfig($application); return $application; }); }
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(); }
/** * @expectedException \Stormpath\Resource\ResourceError */ public function testDelete() { $application = \Stormpath\Resource\Application::create(array('name' => 'Yet Another App' . md5(time() . microtime() . uniqid()))); $this->assertInstanceOf('Stormpath\\Resource\\Application', $application); $this->assertContains('Yet Another App', $application->name); $href = $application->href; $application->delete(); \Stormpath\Resource\Application::get($href); }
/** * @test */ public function it_can_add_an_account_store_mapping() { $application = \Stormpath\Resource\Application::instantiate(['name' => makeUniqueName('OrgTest'), 'description' => 'Description of Main App', 'status' => 'enabled']); $application = self::createResource(\Stormpath\Resource\Application::PATH, $application); $accountStoreMapping = \Stormpath\Resource\AccountStoreMapping::instantiate(['organization' => self::$organization, 'accountStore' => self::$directory, 'isDefaultAccountStore' => true, 'isDefaultGroupStore' => true]); $test1 = self::$organization->createOrganizationAccountStoreMapping($accountStoreMapping); $this->assertInstanceOf('\\Stormpath\\Resource\\AccountStoreMapping', $test1); $accountStoreMapping = \Stormpath\Resource\AccountStoreMapping::instantiate(['accountStore' => self::$organization, 'application' => $application, 'isDefaultAccountStore' => true]); $test2 = $application->createAccountStoreMapping($accountStoreMapping); $this->assertInstanceOf('\\Stormpath\\Resource\\AccountStoreMapping', $test2); $org = Organization::get(self::$organization->href); $this->assertNotNull($org->accountStoreMappings->href); $this->assertInstanceOf('Stormpath\\Resource\\AccountStore', $org->defaultAccountStoreMapping); $this->assertInstanceOf('Stormpath\\Resource\\AccountStore', $org->defaultGroupStoreMapping); $asm = $org->accountStoreMappings; foreach ($asm as $mapping) { $this->assertEquals($org->href, $mapping->organization->href); $this->assertEquals(self::$directory->href, $mapping->accountStore->href); } $app = Application::get($application->href); $this->assertNotNull($app->accountStoreMappings->href); $asm = $app->accountStoreMappings; foreach ($asm as $mapping) { $this->assertEquals($app->href, $mapping->application->href); $this->assertEquals(self::$organization->href, $mapping->accountStore->href); } $application->delete(); }
$url = $application->createIdSiteUrl(['path' => '/#/register', 'callbackUri' => 'http://*****:*****@get_post_by_user'); // *1+.获取一个用户(user_id)发布的所有post详细信息 $app->post('/get_postlist_by_user', 'DataController@get_postlist_by_user'); // *2.从post_id反推出用户id (返回obj) 和所有信息(返回array) $app->post('/get_userid_by_post', 'DataController@get_userid_by_post'); //*2+.POST获取 Post_id 反推 user详细信息 (return array)
public function testFacebookProviderAccount() { $requestExecutor = $this->getMock('\\Stormpath\\Http\\RequestExecutor'); $apiKey = $this->getMock('\\Stormpath\\ApiKey', array(), array("mockId", "mockSecret")); $cacheManager = $this->getMock('\\Stormpath\\Cache\\CacheManager'); $dataStore = $this->getMock('\\Stormpath\\DataStore\\DefaultDataStore', array('create'), array($requestExecutor, $apiKey, $cacheManager)); $accessToken = "4/XrsKzIJuy3ye57eqbanlQDN1wZHYfaUV-MFyC6dRjRw.wnCoOEKwnlwXXmXvfARQvthKMCbPmgI"; $providerAccountRequest = new \Stormpath\Provider\FacebookProviderAccountRequest(array("accessToken" => $accessToken)); $providerData = $providerAccountRequest->getProviderData($dataStore); $this->assertEquals(FacebookProvider::FACEBOOK_PROVIDER_ID, $providerData->providerId); $this->assertEquals($accessToken, $providerData->accessToken); $providerAccountAccess = $dataStore->instantiate(Stormpath::PROVIDER_ACCOUNT_ACCESS); $providerAccountAccess->providerData = $providerData; $application = new Application($dataStore); $providerAccountResult = $this->getMock('\\Stormpath\\Resource\\ProviderAccountResult'); $dataStore->expects($this->once())->method('create')->with($this->equalTo($application->getHref() . '/' . Account::PATH), $this->equalTo($providerAccountAccess), $this->equalTo(Stormpath::PROVIDER_ACCOUNT_RESULT))->will($this->returnValue($providerAccountResult)); $returnedResult = $application->getAccount($providerAccountRequest); $this->assertEquals($providerAccountResult, $returnedResult); }
/** * @expectedException \Stormpath\Resource\ResourceError */ public function testDelete() { $application = \Stormpath\Resource\Application::create(array('name' => makeUniqueName('ApplicationTest testDelete'))); $this->assertInstanceOf('Stormpath\\Resource\\Application', $application); $this->assertContains('testDelete', $application->name); $href = $application->href; $application->delete(); \Stormpath\Resource\Application::get($href); }
public function testDelete() { $application = \Stormpath\Resource\Application::instantiate(array('name' => makeUniqueName('AccountStoreMappingTest Test Delete'))); self::createResource(\Stormpath\Resource\Application::PATH, $application); $accountStoreMappingWithDir = \Stormpath\Resource\AccountStoreMapping::create(array('accountStore' => self::$directory, 'application' => $application)); $href = $accountStoreMappingWithDir->href; $accountStoreMapping = \Stormpath\Resource\AccountStoreMapping::get($href); $this->assertInstanceOf('Stormpath\\Resource\\AccountStoreMapping', $accountStoreMapping); $this->assertInstanceOf('Stormpath\\Resource\\Directory', $accountStoreMapping->accountStore); $accountStoreMapping->delete(); try { \Stormpath\Resource\AccountStoreMapping::get($href); $application->delete(); $this->fail('Should have thrown a ResourceError.'); } catch (\Stormpath\Resource\ResourceError $re) { $this->assertTrue(true); } $application->delete(); }
private function registerApplication() { $this->app->singleton('stormpath.application', function () { $this->guardAgainstInvalidApplicationHref(); // return $this->app['cache.store']->rememberForever('stormpath.application', function() { $application = \Stormpath\Resource\Application::get(config('stormpath.application.href')); return $application; // }); }); }
public function setupStormpathApplication() { $this->application = \Stormpath\Resource\Application::instantiate(array('name' => 'Test Application - ' . microtime(), 'description' => 'Description of Main App', 'status' => 'enabled')); self::createResource(\Stormpath\Resource\Application::PATH, $this->application, array('createDirectory' => true)); config(['stormpath.application.href' => $this->application->href]); }
/** * @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(); }
/** @test */ public function an_application_should_allow_setting_authorized_callback_uri() { $application = \Stormpath\Resource\Application::create(array('name' => makeUniqueName('ApplicationTest authorizedCallbackUri'))); $application->setAuthorizedCallbackUris(['http://myapplication.com/whatever/callback', 'http://myapplication.com/whatever/callback2']); $application->save(); $application = \Stormpath\Resource\Application::get($application->href); $this->assertCount(2, $application->authorizedCallbackUris); $application->delete(); }