xsolve-pl / xsolve-google-auth-bundle
XSolve Google Auth Bundle to provide signing in to FOSUserBundle with Google Auth
Requires
- friendsofsymfony/user-bundle: v1.3.3
- google/apiclient: ~1.0.0@beta
This package is not auto-updated.
Last update: 2024-12-17 06:32:26 UTC
README
This bundle allows user to sign in via Google Auth 2.0 API to FOSUserBundle.
It includes:
- Google API integration
- Creating new user when it's necessary
- Signing in
Installation
-
Install and configure FOSUserBundle
https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/index.md
-
Add to composer.json
"require": { "xsolve-pl/xsolve-google-auth-bundle": "1.0.*" },
-
Install dependencies
composer install
-
Run the bundle in app/AppKernel.php
public function registerBundles() { return array( // ... new Xsolve\GoogleAuthBundle\XsolveGoogleAuthBundle(), ); }
-
Add to routing.yml
xsolve_google_auth: resource: "@XsolveGoogleAuthBundle/Controller/" type: annotation prefix: /
-
Register your service in https://code.google.com/apis/console/b/0/ an configure parameters.yml and add
xsolve_google_auth: name: Xsolve test application client_id: "4429041xxxx.apps.googleusercontent.com" client_secret: "xrAbfJ7wmOBZbYU3TyDxxxxx" redirect_uri: "http://testapp.xsolve.pl/oauth2callback" dev_key: xsolvetestapplication
success_authorization_redirect_url: _welcome failure_authorization_redirect_url: _welcome scopes: - profile - email autoregistration: false autoregistration_domains: []
-
Add access controls to security.yml
access_control: - { path: ^/oauth2callback, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/googleauthlogin, role: IS_AUTHENTICATED_ANONYMOUSLY }
Usage
After configuring a bundle you can go to /oauth2callback page and the browser should redirect to google access page.
Configuration options
Configuration can be adjusted in app/config/config.yml
xsolve_google_auth:
name: Xsolve test application #name of application from google console
client_id: "4429041xxxx.apps.googleusercontent.com" #client id of application from google console
client_secret: "xrAbfJ7wmOBZbYU3TyDxxxxx" #client secret key of application from google console
redirect_uri: "http://testapp.xsolve.pl/oauth2callback" #redirect uri of application from google console
dev_key: xsolvetestapplication #your developmnent's application name from google console
scopes: #data which application needs from google API
- profile
- email
success_authorization_redirect_url: _welcome #url key inside Symfony where user should be redirected after successful sign in
failure_authorization_redirect_url: _welcome #url key inside Symfony where user should be redirected after failure sign in
autoregistration: false #true|false - if false than user will be registered into system automaticaly
autoregistration_domains: #array may be empty. If autoregistration is true you can allow to register users only from selected domains
- xsolve.pl
Add link to Twig template
Add this link to your Twig template to force login action with Google OAuth 2.0 :
<a href="{{ path('xsolve_googleauth_googleauthorization_authorization') }}">Login with Google</a>
or
<a href="{{ path('xsolve_googleauth_googleauthorization_authorization_1') }}">Login with Google</a>