Permalink
83 lines (59 sloc) 2.42 KB

Step 1: Setting up the bundle

A) Add HWIOAuthBundle to your project

composer require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle

Why php-http/guzzle6-adapter? We are decoupled from any HTTP messaging client thanks to HTTPlug.

Why php-http/httplug-bundle? This is the official Symfony integration of HTTPlug. This makes it possible to provide the required HTTP client and message factory with ease. The dependency is optional but you will have to provide your own services if you don't set it up.

B) Enable the bundle

Enable the bundle in the kernel:

// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Http\HttplugBundle\HttplugBundle(), // If you require the php-http/httplug-bundle package.
        new HWI\Bundle\OAuthBundle\HWIOAuthBundle(),
    );
}

If you don't use HttplugBundle, you will have to configure your own client service.

C) Import the routing

Import the redirect.xml and login.xml routing files in your own routing file.

# app/config/routing.yml
hwi_oauth_redirect:
    resource: "@HWIOAuthBundle/Resources/config/routing/redirect.xml"
    prefix:   /connect

hwi_oauth_connect:
    resource: "@HWIOAuthBundle/Resources/config/routing/connect.xml"
    prefix:   /connect

hwi_oauth_login:
    resource: "@HWIOAuthBundle/Resources/config/routing/login.xml"
    prefix:   /login

Note:

Due to some deprecation, Symfony 4.1 users should import the following routing files instead:

# app/config/routing.yml
hwi_oauth_redirect:
    resource: "@HWIOAuthBundle/Resources/config/routing/redirect_41.xml"
    prefix:   /connect

hwi_oauth_connect:
    resource: "@HWIOAuthBundle/Resources/config/routing/connect_41.xml"
    prefix:   /connect

hwi_oauth_login:
    resource: "@HWIOAuthBundle/Resources/config/routing/login_41.xml"
    prefix:   /login

Note:

To prevent strange issues, this route should be imported before your custom ones.

Continue to the next step!

When you're done. Continue by configuring the resource owners you want to use in your application!

Step 2: Configuring resource owners (Facebook, GitHub, Google, Windows Live and others