PHPackages                             mstaples/google-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. mstaples/google-bundle

ActiveSymfony-bundle[API Development](/categories/api)

mstaples/google-bundle
======================

Integrate Google Services into Symfony 2 app.

0.1.x-dev(11y ago)06MITPHP &gt;=5.3.2

Since Jul 7Pushed 11y ago1 watchersCompare

[ Source](https://github.com/mstaples/GoogleBundle)[ Packagist](https://packagist.org/packages/mstaples/google-bundle)[ Docs](http://bitgandtter.github.com)[ RSS](/packages/mstaples-google-bundle/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (4)Versions (2)Used By (0)

Introduction
============

[](#introduction)

This Bundle is an old version of the bitgandtter/google-bundle. I am maintaining this independently as this version is used in my current project. Note: this branch is compatible with releases of Symfony2 &gt;= v2.3

Installation
============

[](#installation)

1. Add this bundle and the Google PHP SDK to your `vendor/` dir:

    - Using the vendors script.

        Add the following lines in your `deps` file::

        ```
        {
        "require": {
            "bitgandtter/google-bundle": "0.1"
        	}
        }

        ```
2. Run the composer to download the bundle

    ```
       $ composer update

    ```
3. Add this bundle to your application's kernel:

    ```
     // app/ApplicationKernel.php
     public function registerBundles()
     {
         return array(
             // ...
             new BIT\GoogleBundle\BITGoogleBundle(),
             // ...
         );
     }

    ```
4. Add the following routes to your application and point them at actual controller actions

    ```
     #application/config/routing.yml
     _security_check:
         pattern:  /login_check
     _security_logout:
         pattern:  /logout

     #application/config/routing.xml

    ```
5. Configure the `google` service in your config:

    ```
     # application/config/config.yml
     bit_google:
       app_name: appName
       client_id: 123456789
       client_secret: s3cr3t
       state: auth
       access_type: online
       scopes: [userinfo.email, userinfo.profile]
       approval_prompt: auto
       callback_url: http://yourdomain.com/login_check?google=true

    ```

NOTE: this extra parameter in the callback\_url is mandatory needed to locate the google firewall

6. Add this configuration if you want to use the `security component`:

    ```
     # application/config/config.yml
     security:
         firewalls:
             public:
                 # since anonymous is allowed users will not be forced to login
                 pattern:   ^/.*
         bit_google:
               provider: google

         access_control:
             - { path: ^/secured/.*, role: [IS_AUTHENTICATED_FULLY] } # This is the route secured with bit_google
             - { path: ^/.*, role: [IS_AUTHENTICATED_ANONYMOUSLY] }

    ```

    You have to add `/secured/` in your routing for this to work. An example would be...

    ```
         _google_secured:
             pattern: /secured/
             defaults: { _controller: AcmeDemoBundle:Welcome:index }

    ```
7. Optionally define a custom user provider class and use it as the provider or define path for login

    ```
     # application/config/config.yml
     security:
         providers:
             # choose the provider name freely
                 google:
                   id: google.user # see "Example Customer User Provider using the BIT\UserBundle" chapter further down

         firewalls:
             public:
                 pattern:   ^/.*
                 bit_google:
                   provider: google
                 anonymous: true
                 logout: true

    ```
8. Optionally use access control to secure specific URLs

    ```
     # application/config/config.yml
     security:
         # ...

         access_control:
             - { path: ^/google/,           role: [ROLE_GOOGLE] }
             - { path: ^/.*,                role: [IS_AUTHENTICATED_ANONYMOUSLY] }

    ```

Include the login button in your templates
------------------------------------------

[](#include-the-login-button-in-your-templates)

Just add the following code in one of your templates:

```
{{ google_login_button() }}

```

Or if you want to use:

```
{% autoescape false %}{{ google_login_url() }}{% endautoescape %}

```

This will get you the login url

Example Customer User Provider using the FOS\\UserBundle
--------------------------------------------------------

[](#example-customer-user-provider-using-the-fosuserbundle)

This requires adding a service for the custom user provider which is then set to the provider id in the "provider" section in the config.yml:

```
services:
    google.user:
  class: class: Acme\MyBundle\Security\User\Provider\googleProvider
  arguments:
      google: @bit_google.api
      userManager: @bit_user.user_manager
      validator: @validator
      em: @doctrine.orm.entity_manager
