Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
server
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
labelabeille
server
Commits
a3985663
Commit
a3985663
authored
May 07, 2016
by
wilhelmhb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handlers for authentication
parent
a9ee2eb0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
0 deletions
+65
-0
src/ApiBundle/Entity/Handler/AuthenticationFailureHandler.php
...ApiBundle/Entity/Handler/AuthenticationFailureHandler.php
+27
-0
src/ApiBundle/Entity/Handler/AuthenticationSuccessHandler.php
...ApiBundle/Entity/Handler/AuthenticationSuccessHandler.php
+38
-0
No files found.
src/ApiBundle/Entity/Handler/AuthenticationFailureHandler.php
0 → 100644
View file @
a3985663
<?php
namespace
ApiBundle\Entity\Handler
;
use
Symfony\Component\HttpFoundation\JsonResponse
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\Security\Core\Exception\AuthenticationException
;
use
Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface
;
/**
* class AuthenticationFailureHandler
*
*/
class
AuthenticationFailureHandler
implements
AuthenticationFailureHandlerInterface
{
/**
* {@inheritdoc}
*/
public
function
onAuthenticationFailure
(
Request
$request
,
AuthenticationException
$exception
)
{
$response
=
new
JsonResponse
([
'success'
=>
false
,
'exception'
=>
json_encode
(
$exception
->
getMessage
()),
'request'
=>
json_encode
(
$request
->
request
->
all
())],
401
);
$response
->
headers
->
set
(
'Content-Type'
,
'application/json'
);
return
$response
;
}
}
?>
src/ApiBundle/Entity/Handler/AuthenticationSuccessHandler.php
0 → 100755
View file @
a3985663
<?php
namespace
ApiBundle\Entity\Handler
;
use
Symfony\Component\HttpFoundation\JsonResponse
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\Security\Core\Authentication\Token\TokenInterface
;
use
Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface
;
use
Symfony\Component\HttpFoundation\RedirectResponse
;
/**
* class AuthenticationSuccessHandler
*
* @author Nicolas Macherey <nicolas.macherey@gmail.com>
*/
class
AuthenticationSuccessHandler
implements
AuthenticationSuccessHandlerInterface
{
/**
* {@inheritdoc}
*/
public
function
onAuthenticationSuccess
(
Request
$request
,
TokenInterface
$token
)
{
$response
=
new
JsonResponse
([
'success'
=>
true
,
'email'
=>
$token
->
getUser
()
->
getUsername
(),
'id'
=>
$token
->
getUser
()
->
getId
(),
'firstname'
=>
$token
->
getUser
()
->
getFirstname
(),
'lastname'
=>
$token
->
getUser
()
->
getLastname
(),],
200
);
$response
->
headers
->
set
(
'Content-Type'
,
'application/json'
);
return
$response
;
// on effectue la redirection
/*$response = new RedirectResponse($this->router->generate('api_pscustomer_me'));
$event->setResponse($response);
//$response->headers->set('Access-Control-Allow-Origin', "http://localhost");
return $response;*/
}
}
?>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment