liip/oneall-bundle

此包已被弃用且不再维护。未建议替代包。

Symfony2 Bundle 用于整合 oneall.com

安装: 179

依赖: 0

建议者: 0

安全: 0

星星: 9

关注者: 48

分支: 9

开放问题: 4

类型:symfony-bundle

1.0.0 2013-07-25 09:03 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:22:50 UTC


README

此包已不再维护。如有需要,请随意分支。

简介

这仍然是一个正在进行中的项目!

此包使 Oneall.com 能够与 Symfony2 集成。代码基于 https://github.com/FriendsOfSymfony/FOSFacebookBundle

请参阅 Oneall 文档: http://docs.oneall.com/plugins/

另外,请参阅官方安全文档,特别是配置的详细信息:https://symfony.ac.cn/doc/current/book/security.html

Build Status

先决条件

此版本需要 Symfony 2.1

安装

  1. 在您的 composer.json 中添加以下行
{
  "require": {
      "liip/oneall-bundle": "dev-master"
  }
}
  1. 运行 composer 以下载包
$ php composer.phar require liip/oneall-bundle
  1. 将此包添加到应用程序的内核
        // app/ApplicationKernel.php
        public function registerBundles()
        {
            return array(
                // ...
                new Liip\OneallBundle\LiipOneallBundle(),
                // ...
            );
        }
  1. 将以下路由添加到应用程序,并指向实际的控制器操作
        #application/config/routing.yml
        liip_oneall_check:
            pattern:  /login_check
        liip_oneall_logout:
            pattern:  /logout
        #application/config/routing.xml
        <route id="liip_oneall_check" pattern="/login_check" />
        <route id="liip_oneall_logout" pattern="/logout" />
  1. 在您的配置中配置 oneall 服务(大部分信息可以从 oneall.com 控制面板中复制出来)
        # application/config/config.yml
        liip_oneall:
            site_subdomain: my_subdomain
            site_public_key: my_not_so_secret_key
            site_private_key: my_s3cr3t_key
            social_links: [linkedin, facebook, github, twitter]
            default_firewall_name: main
            callback_path: /foo
        # application/config/config.xml
        <liip_oneall:api
            site_subdomain="my_subdomain"
            site_public_key="my_not_so_secret_key"
            site_private_key="my_s3cr3t_key"
            default_firewall_name="main"
            callback_path="/foo"
        >
              <social-links>linkedin</social-links>
              <social-links>facebook</social-links>
              <social-links>github</social-links>
              <social-links>twitter</social-links>
        </liip_oneall:api>
 > Note you only need to specify either ``default_firewall_name`` or ``callback_path``.
 The ``callback_path`` can either be a relative path or a route name.
  1. 如果您想使用 security component,请添加此配置
        # application/config/config.yml
        security:
            firewalls:
                public:
                    # since anonymous is allowed users will not be forced to login
                    pattern:   ^/.*
                    liip_oneall:
                        check_path: liip_oneall_check
                    anonymous: true
                    logout:
                        handlers: ["liip_oneall.logout_handler"]

            access_control:
                - { path: ^/secured/.*, role: [IS_AUTHENTICATED_FULLY] } # This is the route secured with liip_oneall
                - { path: ^/.*, role: [IS_AUTHENTICATED_ANONYMOUSLY] }
 You have to add `/secured/` in your routing for this to work. An example would be...
            liip_oneall_secured:
                pattern: /secured/
                defaults: { _controller: AcmeDemoBundle:Welcome:index }
  1. 可选地定义自定义用户提供者类并将其用作提供者或定义登录路径。为 FOSUserBundle 集成提供了默认实现
        # application/config/config.yml
        security:
            providers:
                # choose the provider name freely
                my_liip_oneall_provider:
                    id: liip_oneall.user_provider   # see "Example Custom User Provider using the FOS\UserBundle" chapter further down

            firewalls:
                public:
                    pattern:   ^/.*
                    liip_oneall:
                        login_path: /login
                        check_path: liip_oneall_check
                        default_target_path: /
                        provider: my_liip_oneall_provider
                    anonymous: true
                    logout:
                        handlers: ["liip_oneall.logout_handler"]
  1. 可选地使用访问控制来保护特定的 URL
        # application/config/config.yml
        security:
            # ...
            
            access_control:
                - { path: ^/oneall/,           role: [ROLE_ONEALL] }
                - { path: ^/.*,                role: [IS_AUTHENTICATED_ANONYMOUSLY] }
The role `ROLE_ONEALL` has to be added in your User class (see Acme\MyBundle\Entity\User::setFBData() below).
> Note that the order of access control rules matters!

设置 JavaScript SDK

包含用于加载 Oneall JavaScript SDK 并使用服务容器中的参数初始化它的模板扩展。要设置 Oneall JavaScript 环境,请将以下内容添加到布局中,在 body 标签打开之后

<!-- inside a twig template -->
{{ oneall_initialize() }}

在模板中包含登录按钮

只需在模板中添加以下代码

<!-- inside a twig template -->
{{ oneall_login_button({'login_container_id': 'some_tag_id'}) }}

请注意,login_container_id 是可选的,默认为 oa_social_login_container

在模板中包含注销 URL

待办事项