2017 © Pedro Peláez
 

symfony-bundle sonata-oauth2-login-bundle

Login via Google with Email Validation in a Sonata Project

image

silasjoisten/sonata-oauth2-login-bundle

Login via Google with Email Validation in a Sonata Project

  • Friday, June 8, 2018
  • by silasjoisten
  • Repository
  • 2 Watchers
  • 0 Stars
  • 4,061 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 22 Versions
  • 93 % Grown

The README.md

silasjoisten/sonata-oauth2-login-bundle

Build Status Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

Installation

composer require silasjoisten/sonata-oauth2-login-bundle

Register the Bundle in app/AppKernel.php:, (*2)

 class AppKernel extends Kernel
 {
     public function registerBundles()
     {
        // ..
        new Http\HttplugBundle\HttplugBundle(),
        new HWI\Bundle\OAuthBundle\HWIOAuthBundle(),
        new SilasJoisten\Sonata\Oauth2LoginBundle\SonataOauth2LoginBundle(),
        // ..
     }

    // ..
}

Configuration

Include the Routing:

SonataOauth2LoginBundle:
    resource: "@SonataOauth2LoginBundle/Resources/config/routing.xml"

Configure the Bundle:

sonata_oauth2_login:
    valid_email_domains: ["@your-domain.com"]
    default_user_roles: ["ROLE_SONATA_ADMIN"]
    #optional value
    custom_emails: 
        test@example.com: ["ROLE_SUPER_ADMIN"]
        test2@example.de: ["ROLE_SONATA_ADMIN"]

You can add as much valid domains as you want, (*3)

Configure the HWIOauthBundle:

# app/config/security.yml

security:
   providers:
      hwi:
         id: sonata_oauth2_login.user.provider

         #...

   firewalls:
      YOUR_FIREWALL:
         #pattern: /admin(.*) REMOVE THIS LINE IF YOU ARE USING SONATA ADMIN
         oauth:
            resource_owners:
               google:         "/login/check-google"
            login_path:        /admin/login                 # For Sonata Admin
            use_forward:       false
            default_target_path: /admin/dashboard           # For Sonata Admin
            failure_path:      /admin/login                 # For Sonata Admin
            oauth_user_provider:
               service:  sonata_oauth2_login.user.provider
# app/config/config.yml

hwi_oauth:
    firewall_names: [YOUR_FIREWALL]
    resource_owners:
        google:
            type:                "google"
            client_id:           "YOUR_CLIENT_ID"
            client_secret:       "YOUR_CLIENT_SECRET"
            scope:               "email profile"
            options:
                csrf: true
                access_type:     offline

Usage

To use the OAuth2 login you just need to call the Twig function to render the button in your login template like this:, (*4)

{{ render_login_button() }}

Optional: You can pass an array inside to to set custom class and value, (*5)

Look and Feel

Look and Feel, (*6)

The Versions

25/09 2017

dev-feature/test-branch

dev-feature/test-branch

Login via Google with Email Validation in a Sonata Project

  Sources   Download

MIT

The Requires

 

The Development Requires

by Silas Joisten

10/04 2017

dev-feature/test-implementation

dev-feature/test-implementation

A OAuth2LoginBundle to sign in Exozet members

  Sources   Download

MIT

The Requires

 

The Development Requires

by Silas Joisten