本文整理汇总了PHP中OAuth2\Server::addStorage方法的典型用法代码示例。如果您正苦于以下问题:PHP Server::addStorage方法的具体用法?PHP Server::addStorage怎么用?PHP Server::addStorage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OAuth2\Server
的用法示例。
在下文中一共展示了Server::addStorage方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: middleware
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: setup
/**
* function to create the OAuth2 Server Object
*/
public function setup(Application $app)
{
// ensure our Sqlite database exists
if (!file_exists($sqliteFile = __DIR__ . '/../../../data/oauth.sqlite')) {
$this->generateSqliteDb();
}
// create PDO-based sqlite storage
$storage = new Pdo(array('dsn' => 'sqlite:' . $sqliteFile));
// create array of supported grant types
$grantTypes = array('authorization_code' => new AuthorizationCode($storage), 'user_credentials' => new UserCredentials($storage), 'refresh_token' => new RefreshToken($storage, array('always_issue_new_refresh_token' => true)));
// instantiate the oauth server
$server = new OAuth2Server($storage, array('enforce_state' => true, 'allow_implicit' => true, 'use_openid_connect' => true, 'issuer' => $_SERVER['HTTP_HOST']), $grantTypes);
$server->addStorage($this->getKeyStorage(), 'public_key');
// add the server to the silex "container" so we can use it in our controllers (see src/OAuth2Demo/Server/Controllers/.*)
$app['oauth_server'] = $server;
/**
* add HttpFoundataionBridge Response to the container, which returns a silex-compatible response object
* @see (https://github.com/bshaffer/oauth2-server-httpfoundation-bridge)
*/
$app['oauth_response'] = new BridgeResponse();
}
示例3: testUsingJwtAccessTokensWithoutPublicKeyStorageThrowsException
/**
* @expectedException LogicException OAuth2\Storage\PublicKeyInterface
**/
public function testUsingJwtAccessTokensWithoutPublicKeyStorageThrowsException()
{
$server = new Server(array(), array('use_jwt_access_tokens' => true));
$server->addGrantType($this->getMock('OAuth2\\GrantType\\GrantTypeInterface'));
$server->addStorage($this->getMock('OAuth2\\Storage\\ClientCredentialsInterface'));
$server->addStorage($this->getMock('OAuth2\\Storage\\ClientCredentialsInterface'));
$server->getTokenController();
}
示例4: testAddingResponseType
public function testAddingResponseType()
{
$storage = $this->getMock('OAuth2\\Storage\\Memory');
$storage->expects($this->any())->method('getClientDetails')->will($this->returnValue(array('client_id' => 'some_client')));
$storage->expects($this->any())->method('checkRestrictedGrantType')->will($this->returnValue(true));
// add with the "code" key explicitly set
$codeType = new AuthorizationCode($storage);
$server = new Server();
$server->addStorage($storage);
$server->addResponseType($codeType);
$request = new Request(array('response_type' => 'code', 'client_id' => 'some_client', 'redirect_uri' => 'http://example.com', 'state' => 'xyx'));
$server->handleAuthorizeRequest($request, $response = new Response(), true);
// the response is successful
$this->assertEquals($response->getStatusCode(), 302);
$parts = parse_url($response->getHttpHeader('Location'));
parse_str($parts['query'], $query);
$this->assertTrue(isset($query['code']));
$this->assertFalse(isset($query['error']));
// add with the "code" key not set
$codeType = new AuthorizationCode($storage);
$server = new Server(array($storage), array(), array(), array($codeType));
$request = new Request(array('response_type' => 'code', 'client_id' => 'some_client', 'redirect_uri' => 'http://example.com', 'state' => 'xyx'));
$server->handleAuthorizeRequest($request, $response = new Response(), true);
// the response is successful
$this->assertEquals($response->getStatusCode(), 302);
$parts = parse_url($response->getHttpHeader('Location'));
parse_str($parts['query'], $query);
$this->assertTrue(isset($query['code']));
$this->assertFalse(isset($query['error']));
}