private function getTestServer()
 {
     $storage = Bootstrap::getInstance()->getMemoryStorage();
     $server = new Server($storage);
     $server->addGrantType(new UserCredentials($storage));
     return $server;
 }
 private function getTestServer()
 {
     $storage = Bootstrap::getInstance()->getMemoryStorage();
     $server = new Server($storage, array('use_openid_connect' => true));
     $server->addGrantType(new AuthorizationCode($storage));
     return $server;
 }
 public function provideClientCredentials()
 {
     $storage = Bootstrap::getInstance()->getMemoryStorage();
     $client_id = 'Test Client ID';
     $client_key = $storage->getClientKey($client_id, "*****@*****.**");
     return array(array($client_id, $client_key));
 }
Пример #4
0
 private function getTestServer($config = array())
 {
     $storage = Bootstrap::getInstance()->getMemoryStorage();
     $server = new Server($storage, $config);
     // Add the two types supported for authorization grant
     $server->addGrantType(new AuthorizationCode($storage));
     return $server;
 }
 private function getTestServer($config = array())
 {
     $config += array('use_openid_connect' => true, 'issuer' => 'test', 'id_lifetime' => 3600);
     $memoryStorage = Bootstrap::getInstance()->getMemoryStorage();
     $responseTypes = array('token' => $token = new AccessToken($memoryStorage, $memoryStorage), 'id_token' => $idToken = new IdToken($memoryStorage, $memoryStorage, $config), 'id_token token' => new IdTokenToken($token, $idToken));
     $server = new Server($memoryStorage, $config, array(), $responseTypes);
     $server->addGrantType(new ClientCredentials($memoryStorage));
     return $server;
 }
 private function getTestServer($config = array())
 {
     $config += array('use_openid_connect' => true, 'issuer' => 'test', 'id_lifetime' => 3600, 'allow_implicit' => true);
     $memoryStorage = Bootstrap::getInstance()->getMemoryStorage();
     $responseTypes = array('code' => $code = new AuthorizationCode($memoryStorage), 'id_token' => $idToken = new IdToken($memoryStorage, $memoryStorage, $config), 'code id_token' => new CodeIdToken($code, $idToken));
     $server = new Server($memoryStorage, $config, array(), $responseTypes);
     $server->addGrantType(new ClientCredentials($memoryStorage));
     return $server;
 }
Пример #7
0
 private function getTestServer()
 {
     $memoryStorage = Bootstrap::getInstance()->getMemoryStorage();
     $storage = array('access_token' => new CryptoTokenStorage($memoryStorage), 'client' => $memoryStorage, 'client_credentials' => $memoryStorage);
     $server = new Server($storage);
     $server->addGrantType(new ClientCredentials($memoryStorage));
     // make the "token" response type a CryptoToken
     $server->addResponseType(new CryptoToken($memoryStorage, $memoryStorage));
     return $server;
 }
Пример #8
0
 private function getTestServer()
 {
     $memoryStorage = Bootstrap::getInstance()->getMemoryStorage();
     $storage = array('access_token' => $memoryStorage, 'client' => $memoryStorage, 'device_code' => $memoryStorage);
     $server = new Server($storage);
     // make the "token" response type a DeviceCode response type
     $config = array('interval' => 5, 'verification_uri' => 'http://mysite.com/device');
     $rsp = new DeviceCodeResponseType($memoryStorage, $config);
     $server->addResponseType($rsp);
     return $server;
 }
Пример #9
0
 public function testScopeStorage()
 {
     $scopeUtil = new Scope();
     $this->assertEquals($scopeUtil->getDefaultScope(), null);
     $scopeUtil = new Scope(array('default_scope' => 'default', 'supported_scopes' => array('this', 'that', 'another')));
     $this->assertEquals($scopeUtil->getDefaultScope(), 'default');
     $this->assertTrue($scopeUtil->scopeExists('this that another', 'client_id'));
     $memoryStorage = new Memory(array('default_scope' => 'base', 'supported_scopes' => array('only-this-one')));
     $scopeUtil = new Scope($memoryStorage);
     $this->assertEquals($scopeUtil->getDefaultScope(), 'base');
     $this->assertTrue($scopeUtil->scopeExists('only-this-one', 'client_id'));
     //Test getting default scopes with a client_id
     $memoryStorage = Bootstrap::getInstance()->getMemoryStorage();
     $scopeUtil = new Scope($memoryStorage);
     $this->assertEquals($scopeUtil->getDefaultScope('Test Default Scope Client ID'), 'clientscope1 clientscope2');
     $this->assertEquals($scopeUtil->getDefaultScope('Test Default Scope Client ID 2'), 'clientscope3');
     $this->assertEquals($scopeUtil->getDefaultScope('Test Default Scope Client ID That Does Not Exist'), null);
 }
 /** @dataProvider provideStorage */
 public function testSetAccessToken($storage)
 {
     if (!$storage instanceof PublicKey) {
         // incompatible storage
         return;
     }
     $crypto = new jwtAccessToken($storage);
     $publicKeyStorage = Bootstrap::getInstance()->getMemoryStorage();
     $encryptionUtil = new Jwt();
     $jwtAccessToken = array('access_token' => rand(), 'expires' => time() + 100, 'scope' => 'foo');
     $token = $encryptionUtil->encode($jwtAccessToken, $storage->getPrivateKey(), $storage->getEncryptionAlgorithm());
     $this->assertNotNull($token);
     $tokenData = $crypto->getAccessToken($token);
     $this->assertTrue(is_array($tokenData));
     /* assert the decoded token is the same */
     $this->assertEquals($tokenData['access_token'], $jwtAccessToken['access_token']);
     $this->assertEquals($tokenData['expires'], $jwtAccessToken['expires']);
     $this->assertEquals($tokenData['scope'], $jwtAccessToken['scope']);
 }
 private function getTestServer($config = array())
 {
     $storage = Bootstrap::getInstance()->getMemoryStorage();
     $server = new Server($storage, $config);
     return $server;
 }
 private function getTestServer()
 {
     $storage = Bootstrap::getInstance()->getMemoryStorage();
     $server = new Server($storage);
     $server->addGrantType(new AuthorizationCode($storage));
     return $server;
 }
Пример #13
0
 /**
  * Test setting "always_issue_new_refresh_token" on a server level
  *
  * @see test/OAuth2/GrantType/RefreshTokenTest::testValidRefreshTokenWithNewRefreshTokenInResponse
  **/
 public function testValidRefreshTokenWithNewRefreshTokenInResponse()
 {
     $storage = Bootstrap::getInstance()->getMemoryStorage();
     $server = new Server($storage, array('always_issue_new_refresh_token' => true));
     $request = TestRequest::createPost(array('grant_type' => 'refresh_token', 'client_id' => 'Test Client ID', 'client_secret' => 'TestSecret', 'refresh_token' => 'test-refreshtoken'));
     $token = $server->grantAccessToken($request, new Response());
     $this->assertTrue(isset($token['refresh_token']), 'refresh token should always refresh');
     $refresh_token = $storage->getRefreshToken($token['refresh_token']);
     $this->assertNotNull($refresh_token);
     $this->assertEquals($refresh_token['refresh_token'], $token['refresh_token']);
     $this->assertEquals($refresh_token['client_id'], $request->request('client_id'));
     $this->assertTrue($token['refresh_token'] != 'test-refreshtoken', 'the refresh token returned is not the one used');
     $used_token = $storage->getRefreshToken('test-refreshtoken');
     $this->assertFalse($used_token, 'the refresh token used is no longer valid');
 }
 private function getTestServer()
 {
     $memoryStorage = Bootstrap::getInstance()->getMemoryStorage();
     $storage = array('access_token' => new JwtAccessTokenStorage($memoryStorage), 'client' => $memoryStorage, 'client_credentials' => $memoryStorage);
     $server = new Server($storage);
     $server->addGrantType(new ClientCredentials($memoryStorage));
     // make the "token" response type a JwtAccessToken
     $config = array('issuer' => 'https://api.example.com');
     $server->addResponseType(new JwtAccessToken($memoryStorage, $memoryStorage, null, $config));
     return $server;
 }
Пример #15
0
 private function getTestServer()
 {
     $this->storage = Bootstrap::getInstance()->getMemoryStorage();
     $server = new Server($this->storage);
     return $server;
 }
 private function getTestServer($config = array())
 {
     $config += array('use_openid_connect' => true, 'issuer' => 'phpunit', 'allow_implicit' => true);
     $storage = Bootstrap::getInstance()->getMemoryStorage();
     $server = new Server($storage, $config);
     return $server;
 }
 private function getTestServer($audience = 'http://myapp.com/oauth/auth')
 {
     $storage = Bootstrap::getInstance()->getMemoryStorage();
     $server = new Server($storage);
     $server->addGrantType(new JwtBearer($storage, $audience, new Jwt()));
     return $server;
 }
Пример #18
0
 private function getTestServer($config = array())
 {
     $config += array('use_openid_connect' => true, 'issuer' => 'test', 'id_lifetime' => 3600);
     $memoryStorage = Bootstrap::getInstance()->getMemoryStorage();
     $memoryStorage->supportedScopes[] = 'email';
     $storage = array('client' => $memoryStorage, 'scope' => $memoryStorage);
     $responseTypes = array('id_token' => new IdToken($memoryStorage, $memoryStorage, $config));
     $server = new Server($storage, $config, array(), $responseTypes);
     $server->addGrantType(new ClientCredentials($memoryStorage));
     return $server;
 }
Пример #19
0
 public function testRefreshTokenConfig()
 {
     // create mock storage
     $storage = Bootstrap::getInstance()->getMemoryStorage();
     $server1 = new Server(array($storage));
     $server2 = new Server(array($storage), array('always_issue_new_refresh_token' => true));
     $server1->getTokenController();
     $refreshToken1 = $server1->getGrantType('refresh_token');
     $server2->getTokenController();
     $refreshToken2 = $server2->getGrantType('refresh_token');
     $reflection1 = new \ReflectionClass($refreshToken1);
     $prop1 = $reflection1->getProperty('config');
     $prop1->setAccessible(true);
     $reflection2 = new \ReflectionClass($refreshToken2);
     $prop2 = $reflection2->getProperty('config');
     $prop2->setAccessible(true);
     // get the private "config" property
     $config1 = $prop1->getValue($refreshToken1);
     $config2 = $prop2->getValue($refreshToken2);
     $this->assertEquals($config1['always_issue_new_refresh_token'], false);
     $this->assertEquals($config2['always_issue_new_refresh_token'], true);
 }
Пример #20
0
 public function provideStorage()
 {
     $memory = Bootstrap::getInstance()->getMemoryStorage();
     $mysql = Bootstrap::getInstance()->getMysqlPdo();
     $sqlite = Bootstrap::getInstance()->getSqlitePdo();
     $mongo = Bootstrap::getInstance()->getMongo();
     $redis = Bootstrap::getInstance()->getRedisStorage();
     // will add multiple storage types later
     return array(array($memory), array($sqlite), array($mysql), array($mongo), array($redis));
 }
 private function getTestServer()
 {
     $storage = Bootstrap::getInstance()->getMemoryStorage();
     $server = new Server($storage);
     $server->addGrantType(new AuthorizationCode($storage));
     // or some other grant type.  This is the simplest
     return $server;
 }
Пример #22
0
 public function testCustomClientAssertionType()
 {
     $request = TestRequest::createPost(array('grant_type' => 'authorization_code', 'client_id' => 'Test Client ID', 'code' => 'testcode'));
     // verify the mock clientAssertionType was called as expected
     $clientAssertionType = $this->getMock('OAuth2\\ClientAssertionType\\ClientAssertionTypeInterface', array('validateRequest', 'getClientId'));
     $clientAssertionType->expects($this->once())->method('validateRequest')->will($this->returnValue(true));
     $clientAssertionType->expects($this->once())->method('getClientId')->will($this->returnValue('Test Client ID'));
     // create mock storage
     $storage = Bootstrap::getInstance()->getMemoryStorage();
     $server = new Server(array($storage), array(), array(), array(), null, null, $clientAssertionType);
     $server->handleTokenRequest($request, $response = new Response());
 }
Пример #23
0
 public function testHttpBasicConfig()
 {
     // create mock storage
     $storage = Bootstrap::getInstance()->getMemoryStorage();
     $server = new Server(array($storage), array('allow_credentials_in_request_body' => false));
     $server->getTokenController();
     $httpBasic = $server->getClientAssertionType();
     $reflection = new \ReflectionClass($httpBasic);
     $prop = $reflection->getProperty('config');
     $prop->setAccessible(true);
     $config = $prop->getValue($httpBasic);
     // get the private "storages" property
     $this->assertEquals($config['allow_credentials_in_request_body'], false);
 }
Пример #24
0
 public function testCreatePdoStorageUsingConfig()
 {
     $config = array('dsn' => sprintf('sqlite://%s', Bootstrap::getInstance()->getSqliteDir()));
     $storage = new Pdo($config);
     $this->assertNotNull($storage->getClientDetails('oauth_test_client'));
 }