benjam1/oauth-security-service-provider

用于与KnpOAuthBundle一起使用的OAuth安全服务提供者。

dev-master 2013-02-26 23:04 UTC

This package is auto-updated.

Last update: 2024-09-19 02:03:40 UTC


README

此提供者允许您将基于https://github.com/KnpLabs/KnpOAuthBundle的OAuth安全认证提供者添加到您的Silex项目中。

安装

使用composer

...
"require": {
    ...
    "benjam1/oauth-security-service-provider": "dev-master"
}

然后运行 php composer.phar install

配置

KnpOAuthBundle依赖于Buzz,因此您首先需要设置一个Buzz客户端

$app['buzz.client.factory'] = $app->protect(function ($client) use ($app) {
    return $app->share(function () use ($client, $app) {
        $clients = array(
            'curl'      => '\Buzz\Client\Curl',
            'multicurl' => '\Buzz\Client\MultiCurl',
            'stream'    => '\Buzz\Client\FileGetContent',
        );

        if (false == isset($clients[$client])) {
            throw new \InvalidArgumentException(sprintf('The client "%s" does not exist, curl, multicurl and stream availables.', $client));
        }

        $client = $clients[$client];

        return new $client();
    });
});

$this['buzz.client'] = $app['buzz.client.factory']('curl');

您可以使用Marc的Silex Buzz扩展: https://github.com/marcw/silex-buzz-extension,但我还没有对其进行测试。

当Buzz设置完成后,您可以配置安全服务

    // app.php

    $app->register(new OAuthSecurityServiceProvider());

    $app['security.firewalls'] = array(
        'front' => array(
            'pattern' => '^.*',
            'oauth' => array(
                'oauth_provider'    => 'google',
                'infos_url'         => 'https://www.googleapis.com/oauth2/v1/userinfo',
                'username_path'     => 'email',
                'scope'             => 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email',
                'login_path'        => '/login',
                'check_path'        => '/login_check',
                'failure_path'      => '/',
                'client_id'         => 'yourclientid,
                'secret'            => 'yourapplicationsecret',
            ),
        ),
    );

添加您的用户提供者(有关详细信息,请参阅http://silex.sensiolabs.org/doc/providers/security.html#defining-a-custom-user-provider)并完成设置。

有关Silex的更多信息: http://silex.sensiolabs.org/.