oauth google

This commit is contained in:
Kayn Ty 2018-04-25 12:33:58 +02:00
parent dfb4fbd340
commit 936a8febe6
9 changed files with 109 additions and 36 deletions

View File

@ -111,7 +111,16 @@
{% else %} {% else %}
{#<a class="btn btn-default btn-block btn-twitter" href="{{ hwi_oauth_login_url('disqus') }}">#}
{#<i class="fa fa-google"></i>#}
{#Via {{ 'disqus' | trans({}, 'HWIOAuthBundle') }}#}
{#</a>#}
<h1 class="text-right"> <h1 class="text-right">
<a class="btn btn-default" href="{{ hwi_oauth_login_url('google') }}">
<i class="fa fa-google"></i>
Via {{ 'google' | trans({}, 'HWIOAuthBundle') }}
</a>
<a class="btn btn-primary" <a class="btn btn-primary"
href="{{ path('fos_user_security_login') }}"> href="{{ path('fos_user_security_login') }}">
<i class="fa fa-key"></i> <i class="fa fa-key"></i>

View File

@ -1,3 +1,28 @@
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
facebook_login:
path: /login/check-facebook
google_login:
path: /login/check-google
disqus_login:
path: /login/check-disqus
twitter_login:
path: /login/check-twitter
## app specific stuff
app_festival: app_festival:
resource: "@AppBundle/Controller/FestivalController.php" resource: "@AppBundle/Controller/FestivalController.php"
type: annotation type: annotation
@ -14,29 +39,6 @@ app_sell_record:
resource: "@AppBundle/Controller/SellRecordController.php" resource: "@AppBundle/Controller/SellRecordController.php"
type: annotation type: annotation
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
facebook_login:
path: /login/check-facebook
google_login:
path: /login/check-google
custom_login:
path: /login/check-custom
twitter_login:
path: /login/check-twitter
app: app:
resource: '@AppBundle/Controller/' resource: '@AppBundle/Controller/'
type: annotation type: annotation

View File

@ -34,6 +34,7 @@ security:
resource_owners: resource_owners:
facebook: "/login/check-facebook" facebook: "/login/check-facebook"
google: "/login/check-google" google: "/login/check-google"
disqus: "/login/check-disqus"
# my_custom_provider: "/login/check-custom" # my_custom_provider: "/login/check-custom"
twitter: "/login/check-twitter" twitter: "/login/check-twitter"
login_path: /login login_path: /login

View File

@ -33,8 +33,13 @@ services:
# AppBundle\Service\ExampleService: # AppBundle\Service\ExampleService:
# arguments: # arguments:
# $someArgument: 'some_value' # $someArgument: 'some_value'
# OAUTH
my.oauth_aware.user_provider.service: my.oauth_aware.user_provider.service:
class: HWI\Bundle\OAuthBundle\Security\Core\User\FOSUBUserProvider class: HWI\Bundle\OAuthBundle\Security\Core\User\FOSUBUserProvider
arguments: arguments:
- '@fos_user.user_manager' - '@fos_user.user_manager'
- ['pass properties as array'] - ['pass properties as array']
my.custom.user_provider:
class: MyBundle\Security\Core\User\MyFOSUBUserProvider
arguments: ['@fos_user.user_manager', { facebook: facebook_id }]

View File

@ -24,10 +24,10 @@
"doctrine/doctrine-bundle": "^1.6", "doctrine/doctrine-bundle": "^1.6",
"doctrine/orm": "^2.5", "doctrine/orm": "^2.5",
"friendsofsymfony/user-bundle": "~2.0", "friendsofsymfony/user-bundle": "~2.0",
"hwi/oauth-bundle": "^0.6.1", "hwi/oauth-bundle": "^0.6.2",
"incenteev/composer-parameter-handler": "^2.0", "incenteev/composer-parameter-handler": "^2.0",
"php-http/guzzle6-adapter": "^1.1", "php-http/guzzle6-adapter": "^1.1",
"php-http/httplug-bundle": "^1.9", "php-http/httplug-bundle": "^1.10",
"sensio/distribution-bundle": "^5.0.19", "sensio/distribution-bundle": "^5.0.19",
"sensio/framework-extra-bundle": "^5.0.0", "sensio/framework-extra-bundle": "^5.0.0",
"symfony/monolog-bundle": "^3.1.0", "symfony/monolog-bundle": "^3.1.0",

2
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "c18164d1db85ea9fbbe32f2bfbea9ebc", "content-hash": "340327e74f4d3713baf607c9a61fc0e9",
"packages": [ "packages": [
{ {
"name": "clue/stream-filter", "name": "clue/stream-filter",

View File

@ -0,0 +1,56 @@
<?php
namespace AppBundle\Security\Core\User;
use HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface;
use HWI\Bundle\OAuthBundle\Security\Core\User\FOSUBUserProvider as BaseFOSUBProvider;
use Symfony\Component\Security\Core\User\UserInterface;
class MyFOSUBUserProvider extends BaseFOSUBProvider {
/**
* {@inheritDoc}
*/
public function connect( UserInterface $user, UserResponseInterface $response ) {
// get property from provider configuration by provider name
// , it will return `facebook_id` in that case (see service definition below)
$property = $this->getProperty( $response );
$username = $response->getUsername(); // get the unique user identifier
//we "disconnect" previously connected users
$existingUser = $this->userManager->findUserBy( [ $property => $username ] );
if ( null !== $existingUser ) {
// set current user id and token to null for disconnect
// ...
$this->userManager->updateUser( $existingUser );
}
// we connect current user, set current user id and token
// ...
$this->userManager->updateUser( $user );
}
/**
* {@inheritdoc}
*/
public function loadUserByOAuthUserResponse( UserResponseInterface $response ) {
$userEmail = $response->getEmail();
$user = $this->userManager->findUserByEmail( $userEmail );
// if null just create new user and set it properties
if ( null === $user ) {
$username = $response->getRealName();
$user = new User();
$user->setUsername( $username );
// ... save user to database
return $user;
}
// else update access token of existing user
$serviceName = $response->getResourceOwner()->getName();
$setter = 'set' . ucfirst( $serviceName ) . 'AccessToken';
$user->$setter( $response->getAccessToken() );//update access token
return $user;
}
}

View File

@ -148,7 +148,7 @@ class PhpIniRequirement extends Requirement
} }
if (null === $helpHtml) { if (null === $helpHtml) {
$helpHtml = sprintf('Set <strong>%s</strong> to <strong>%s</strong> in php.ini<a class="btn btn-primary" href="#phpini">*</a>.', $helpHtml = sprintf('Set <strong>%s</strong> to <strong>%s</strong> in php.ini<a href="#phpini">*</a>.',
$cfgName, $cfgName,
$evaluation ? 'on' : 'off' $evaluation ? 'on' : 'off'
); );
@ -419,7 +419,7 @@ class SymfonyRequirements extends RequirementCollection
$this->addRequirement( $this->addRequirement(
is_dir(__DIR__.'/../vendor/composer'), is_dir(__DIR__.'/../vendor/composer'),
'Vendor libraries must be installed', 'Vendor libraries must be installed',
'Vendor libraries are missing. Install composer following instructions from <a class="btn btn-primary" href="http://getcomposer.org/">http://getcomposer.org/</a>. '. 'Vendor libraries are missing. Install composer following instructions from <a href="http://getcomposer.org/">http://getcomposer.org/</a>. '.
'Then run "<strong>php composer.phar install</strong>" to install them.' 'Then run "<strong>php composer.phar install</strong>" to install them.'
); );
@ -443,7 +443,7 @@ class SymfonyRequirements extends RequirementCollection
$this->addPhpIniRequirement( $this->addPhpIniRequirement(
'date.timezone', true, false, 'date.timezone', true, false,
'date.timezone setting must be set', 'date.timezone setting must be set',
'Set the "<strong>date.timezone</strong>" setting in php.ini<a class="btn btn-primary" href="#phpini">*</a> (like Europe/Paris).' 'Set the "<strong>date.timezone</strong>" setting in php.ini<a href="#phpini">*</a> (like Europe/Paris).'
); );
} }
@ -458,7 +458,7 @@ class SymfonyRequirements extends RequirementCollection
$this->addRequirement( $this->addRequirement(
isset($timezones[@date_default_timezone_get()]), isset($timezones[@date_default_timezone_get()]),
sprintf('Configured default timezone "%s" must be supported by your installation of PHP', @date_default_timezone_get()), sprintf('Configured default timezone "%s" must be supported by your installation of PHP', @date_default_timezone_get()),
'Your default timezone is not supported by PHP. Check for typos in your <strong>php.ini</strong> file and have a look at the list of deprecated timezones at <a class="btn btn-primary" href="http://php.net/manual/en/timezones.others.php">http://php.net/manual/en/timezones.others.php</a>.' 'Your default timezone is not supported by PHP. Check for typos in your <strong>php.ini</strong> file and have a look at the list of deprecated timezones at <a href="http://php.net/manual/en/timezones.others.php">http://php.net/manual/en/timezones.others.php</a>.'
); );
} }
@ -522,7 +522,7 @@ class SymfonyRequirements extends RequirementCollection
create_function('$cfgValue', 'return false !== stripos($cfgValue, "phar");'), create_function('$cfgValue', 'return false !== stripos($cfgValue, "phar");'),
false, false,
'suhosin.executor.include.whitelist must be configured correctly in php.ini', 'suhosin.executor.include.whitelist must be configured correctly in php.ini',
'Add "<strong>phar</strong>" to <strong>suhosin.executor.include.whitelist</strong> in php.ini<a class="btn btn-primary" href="#phpini">*</a>.' 'Add "<strong>phar</strong>" to <strong>suhosin.executor.include.whitelist</strong> in php.ini<a href="#phpini">*</a>.'
); );
} }
@ -540,7 +540,7 @@ class SymfonyRequirements extends RequirementCollection
create_function('$cfgValue', 'return $cfgValue > 100;'), create_function('$cfgValue', 'return $cfgValue > 100;'),
true, true,
'xdebug.max_nesting_level should be above 100 in php.ini', 'xdebug.max_nesting_level should be above 100 in php.ini',
'Set "<strong>xdebug.max_nesting_level</strong>" to e.g. "<strong>250</strong>" in php.ini<a class="btn btn-primary" href="#phpini">*</a> to stop Xdebug\'s infinite recursion protection erroneously throwing a fatal error in your project.' 'Set "<strong>xdebug.max_nesting_level</strong>" to e.g. "<strong>250</strong>" in php.ini<a href="#phpini">*</a> to stop Xdebug\'s infinite recursion protection erroneously throwing a fatal error in your project.'
); );
} }
@ -558,7 +558,7 @@ class SymfonyRequirements extends RequirementCollection
create_function('$cfgValue', 'return (int) $cfgValue === 0;'), create_function('$cfgValue', 'return (int) $cfgValue === 0;'),
true, true,
'string functions should not be overloaded', 'string functions should not be overloaded',
'Set "<strong>mbstring.func_overload</strong>" to <strong>0</strong> in php.ini<a class="btn btn-primary" href="#phpini">*</a> to disable function overloading by the mbstring extension.' 'Set "<strong>mbstring.func_overload</strong>" to <strong>0</strong> in php.ini<a href="#phpini">*</a> to disable function overloading by the mbstring extension.'
); );
} }
@ -707,7 +707,7 @@ class SymfonyRequirements extends RequirementCollection
create_function('$cfgValue', 'return (int) $cfgValue === 0;'), create_function('$cfgValue', 'return (int) $cfgValue === 0;'),
true, true,
'intl.error_level should be 0 in php.ini', 'intl.error_level should be 0 in php.ini',
'Set "<strong>intl.error_level</strong>" to "<strong>0</strong>" in php.ini<a class="btn btn-primary" href="#phpini">*</a> to inhibit the messages when an error occurs in ICU functions.' 'Set "<strong>intl.error_level</strong>" to "<strong>0</strong>" in php.ini<a href="#phpini">*</a> to inhibit the messages when an error occurs in ICU functions.'
); );
} }
@ -735,7 +735,7 @@ class SymfonyRequirements extends RequirementCollection
$this->addRecommendation( $this->addRecommendation(
$this->getRealpathCacheSize() >= 5 * 1024 * 1024, $this->getRealpathCacheSize() >= 5 * 1024 * 1024,
'realpath_cache_size should be at least 5M in php.ini', 'realpath_cache_size should be at least 5M in php.ini',
'Setting "<strong>realpath_cache_size</strong>" to e.g. "<strong>5242880</strong>" or "<strong>5M</strong>" in php.ini<a class="btn btn-primary" href="#phpini">*</a> may improve performance on Windows significantly in some cases.' 'Setting "<strong>realpath_cache_size</strong>" to e.g. "<strong>5242880</strong>" or "<strong>5M</strong>" in php.ini<a href="#phpini">*</a> may improve performance on Windows significantly in some cases.'
); );
} }

View File

@ -410,7 +410,7 @@ $hasMinorProblems = (bool) count($minorProblems);
<ul class="symfony-install-continue"> <ul class="symfony-install-continue">
<?php if ($hasMajorProblems || $hasMinorProblems): ?> <?php if ($hasMajorProblems || $hasMinorProblems): ?>
<li><a class="btn btn-primary" href="config.php">Re-check configuration</a></li> <li><a href="config.php">Re-check configuration</a></li>
<?php endif; ?> <?php endif; ?>
</ul> </ul>
</div> </div>