コード例 #1
0
 public function middleware($req, $res)
 {
     $this->app['oauth_server'] = function ($c) {
         $storage = new IdealistStorage();
         $storage->injectApp($c);
         $server = new Server($storage);
         // password grant type
         $grantType = new UserCredentials($storage);
         $server->addGrantType($grantType);
         // JWT access token response type
         $config = $c['config']->get('oauth2');
         $jwtResponseType = new JwtAccessToken($storage, $storage, null, $config);
         $server->addResponseType($jwtResponseType);
         return $server;
     };
     $this->app['oauth_resource'] = function ($c) {
         $server = new Server();
         // no private key is necessary for the resource server
         $keyStorage = new Memory(['keys' => ['public_key' => file_get_contents(INFUSE_BASE_DIR . '/jwt_pubkey.pem')]]);
         $storage = new JwtAccessTokenStorage($keyStorage);
         $server->addStorage($storage, 'access_token');
         return $server;
     };
     // attempt to authenticate the user when an API request is made
     if ($req->isApi()) {
         $this->authenticateApiRequest();
     }
 }
コード例 #2
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;
 }
コード例 #3
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;
 }
コード例 #4
0
 public function testUsingOpenIDConnectWithAllowImplicitAndAccessTokenResponseTypeIsOkay()
 {
     $client = $this->getMock('OAuth2\\Storage\\ClientInterface');
     $userclaims = $this->getMock('OAuth2\\OpenID\\Storage\\UserClaimsInterface');
     $pubkey = $this->getMock('OAuth2\\Storage\\PublicKeyInterface');
     // $token = $this->getMock('OAuth2\Storage\AccessTokenInterface');
     $server = new Server(array($client, $userclaims, $pubkey), array('use_openid_connect' => true, 'issuer' => 'someguy', 'allow_implicit' => true));
     $token = $this->getMock('OAuth2\\ResponseType\\AccessTokenInterface');
     $server->addResponseType($token, 'token');
     $server->getAuthorizeController();
     $this->assertInstanceOf('OAuth2\\OpenID\\ResponseType\\IdTokenInterface', $server->getResponseType('id_token'));
     $this->assertInstanceOf('OAuth2\\OpenID\\ResponseType\\IdTokenTokenInterface', $server->getResponseType('id_token token'));
 }
コード例 #5
0
 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;
 }
コード例 #6
0
 /**
  * @expectedException InvalidArgumentException OAuth2\ResponseType\AuthorizationCodeInterface
  **/
 public function testAddingUnknownResponseTypeThrowsException()
 {
     $server = new Server();
     $server->addResponseType($this->getMock('OAuth2\\ResponseType\\ResponseTypeInterface'));
 }