antwebes/chatea-client-bundle

ChateaClient库的Symfony2扩展包,使使用api.chatea.net的API变得简单


README

ChateaClient库的Symfony2扩展包,使使用api.chatea.net的API变得简单

安装

  1. 将Bundle添加到AppKernel.php ( ChateaClientBundle 和 ChateaSecureBundle )

    new Ant\Bundle\ChateaClientBundle\ChateaClientBundle() new Ant\Bundle\ChateaSecureBundle\ChateaSecureBundle()

  2. 不需要添加配置文件或routing.yml

antwebes_chateclient:
    resource: '@ChateaClientBundle/Resources/config/routing.xml'
    prefix:   /  
  1. 在app/config/config.yml中配置应用程序的client_id和secret
chatea_secure:
    app_auth:
        client_id: %chatea_client_id%
        secret: %chatea_secret_id%
        enviroment: %chatea_enviroment%
    api_endpoint: %api_endpoint%

chatea_client:
    app_auth:
        client_id: %chatea_client_id%
        secret: %chatea_secret_id%
    api_endpoint: %api_endpoint%
    app_id: %chatea_app_id%
    authenticate_client_as_guest: true|false #optional (by deafault false) to indicate if client authenticates as guest. In case of false it authenticates with client credentials
<<<<<<< HEAD
    visits_limit: INTEGER #optional (by default 3) the number of the last N visits to show in the welcome login page
=======
    register_with_profile: true|false (by default true) to indicate if we whant to take the register profile step
    can_skip_register_profile: true|false (by default true) to indicat if we allow the skip button in the register profile page
>>>>>>> no_skip_register_register_end_step
    
beelab_recaptcha2:
    site_key:  %recaptcha_public_key%
    secret: %recaptcha_private_key%
    enabled: %recaptcha_enabled%
  1. 在app/config/security.yml中配置firewall
security:
    providers:
        antwebs_chateaclient_provider:
            id: antwebs_chateaclient_user_provider

    firewalls:
        dev:
            pattern:  ^/(_(profiler|wdt)|css|images|js)/
            security: false

        login:
            pattern:  ^/auth/login$
            security: false


        secured_area:
            pattern:    ^/
            anonymous: ~
            antwebs_chateaclient_login:
                check_path: _security_check
                login_path: _antwebes_chateaclient_login
                provider: antwebs_chateaclient_provider
            logout:
                invalidate_session: false
                path:   _antwebes_chateaclient_logout
                target: nombre_ruta_a_derigir_tras_logout
                handlers: [antwewebs_revoke_access_on_logout_handler]

认证

默认情况下,所有对apichatea的调用都使用应用程序的用户进行。

如果您想调用需要登录用户进行认证的apichatea,请使用@APIUser注解。

实现于

Ant\Bundle\ChateaClientBundle\EventListener\AuthTokenUpdaterListener;

该注解会检查用户是否已认证,如果是,将使用已认证用户进行apichatea的调用。示例

namespace Acme\MiBundel\Controller;
use Ant\Bundle\ChateaClientBundle\Security\Authentication\Annotation\APIUser;

class UsuarioController
{
    /**
     * @APIUser
     *
     */
    public function actualizarNombreUsuarioAction()
    {
        //código
    }
}

如果控制器中的所有方法都需要已登录用户,可以在类中添加该注解。示例

namespace Acme\MiBundel\Controller;
use Ant\Bundle\ChateaClientBundle\Security\Authentication\Annotation\APIUser;

/**
 * @APIUser
 *
 */
class AreaRestringidaController
{
    public function accion1Action()
    {
        //código
    }

    public function accion2Action()
    {
        //código
    }
}

该注解由监听器Ant\Bundle\ChateaClientBundle\EventListener\AuthTokenUpdaterListener处理,该监听器监听控制器事件,以确定是否需要根据需要更新用户的access token。

使欢迎登录页面生效

为了使欢迎登录页面生效,您必须配置twig全局变量boilerplate_users_base_urlboilerplate_channels_base_url。例如

twig:
    globals:
        boilerplate_users_base_url: http://myboilerplate.com/users
        boilerplate_channels_base_url: http://myboilerplate.com/channels

为了在登录后重定向用户到欢迎页面,请在firewall中配置default_target_pathchatea_client_welcome,并将always_use_default_target_path设置为true