-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
vl
committed
Jan 16, 2017
0 parents
commit e928935
Showing
25 changed files
with
6,136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.idea | ||
/vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Playtini\Bundle\AuthBundle\Controller; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
|
||
/** | ||
* ApiController | ||
*/ | ||
class ApiController extends Controller | ||
{ | ||
/** | ||
* Provides key that can be used to connect to other services with AuthBundle | ||
* | ||
* @return JsonResponse {api_key: string} | ||
*/ | ||
public function keyAction() | ||
{ | ||
$username = $this->getUser()->getUsername(); | ||
$apiKey = $this->get('playtini.auth.security.api_key_user_provider')->getHash($username); | ||
|
||
return JsonResponse::create([ | ||
'api_key' => $username . '~' . $apiKey, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
namespace Playtini\Bundle\AuthBundle\Controller; | ||
|
||
use Symfony\Component\HttpFoundation\Cookie; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class GoogleController extends Controller | ||
{ | ||
/** | ||
* Link to this controller to start the "connect" process | ||
* | ||
* @param Request $request | ||
* @return Response | ||
*/ | ||
public function loginAction(Request $request) | ||
{ | ||
$link = $this->get('oauth2.registry')->getClient('google')->getOAuth2Provider()->getAuthorizationUrl(); | ||
|
||
if (!$request->cookies->get('logout')) { | ||
return RedirectResponse::create($link); | ||
} | ||
|
||
$response = new Response(); | ||
$response->headers->clearCookie('logout'); | ||
|
||
return $this->render('AuthBundle::login.html.twig', [ | ||
'link' => $link | ||
], $response); | ||
} | ||
|
||
/** | ||
* After going to Facebook, you're redirect back here | ||
* because this is the "redirect_route" you configured | ||
* in services.yml | ||
* | ||
* @param Request $request | ||
* @return Response | ||
*/ | ||
public function loginCheckAction(Request $request) | ||
{ | ||
// ** if you want to *authenticate* the user, then | ||
// leave this method blank and create a Guard authenticator | ||
} | ||
|
||
public function logoutAction() | ||
{ | ||
// will never be executed | ||
} | ||
|
||
/** | ||
* @return RedirectResponse | ||
*/ | ||
public function forceLogoutAction() | ||
{ | ||
$response = new RedirectResponse($this->get('router')->generate('mailer_auth_security_logout')); | ||
$response->headers->setCookie(new Cookie('logout', 1, '+1 hour')); | ||
|
||
return $response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace Playtini\Bundle\AuthBundle\DependencyInjection; | ||
|
||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; | ||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; | ||
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||
|
||
class AuthExtension extends Extension implements PrependExtensionInterface | ||
{ | ||
/** | ||
* @param ContainerBuilder $container | ||
*/ | ||
public function prepend(ContainerBuilder $container) | ||
{ | ||
$config = [ | ||
'clients' => [ | ||
'google' => [ | ||
// must be "google" - it activates that type! | ||
'type' => 'google', | ||
// add and configure client_id and client_secret in parameters.yml | ||
'client_id' => $container->getParameter('google_app_id'), | ||
'client_secret' => $container->getParameter('google_app_secret'), | ||
// a route name you'll create | ||
'redirect_route' => 'playtini_auth_connect_google_check', | ||
'redirect_params' => [], | ||
// Optional value for sending access_type parameter. More detail: https://developers.google.com/identity/protocols/OAuth2WebServer#offline | ||
'access_type' => 'online', | ||
// Optional value for sending hd parameter. More detail: https://developers.google.com/accounts/docs/OAuth2Login#hd-param | ||
//'hosted_domain' => 'yourdomain.com', | ||
// whether to check OAuth2 "state": defaults to true | ||
'use_state' => false | ||
] | ||
] | ||
]; | ||
$container->prependExtensionConfig('knpu_oauth2_client', $config); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function load(array $configs, ContainerBuilder $container) | ||
{ | ||
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); | ||
$loader->load('services.yml'); | ||
} | ||
} |
Oops, something went wrong.