Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
reminec
Limaju Server Symfony
Commits
c690d912
Commit
c690d912
authored
Oct 04, 2020
by
reminec
Browse files
Refacto auth
parent
5488664f
Pipeline
#343244
failed with stage
in 2 minutes and 39 seconds
Changes
8
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
config/packages/lexik_jwt_authentication.yaml
View file @
c690d912
...
...
@@ -2,3 +2,4 @@ lexik_jwt_authentication:
secret_key
:
'
%env(resolve:JWT_SECRET_KEY)%'
public_key
:
'
%env(resolve:JWT_PUBLIC_KEY)%'
pass_phrase
:
'
%env(JWT_PASSPHRASE)%'
user_identity_field
:
uuid
config/packages/security.yaml
View file @
c690d912
...
...
@@ -27,25 +27,29 @@ security:
pattern
:
^/api/docs?(?:[.](?:html|xml|json|ya?ml))?$
security
:
false
main
:
pattern
:
^/api
provider
:
app_user_provider
api
:
pattern
:
^/api/
stateless
:
true
security
:
true
# Any one can request api
anonymous
:
true
http_basic
:
realm
:
"
Limaju's
Authentication
Desk"
json_login
:
check_path
:
/api/authentication_token
username_path
:
username
password_path
:
password
success_handler
:
lexik_jwt_authentication.handler.authentication_success
failure_handler
:
lexik_jwt_authentication.handler.authentication_failure
anonymous
:
true
provider
:
app_user_provider
guard
:
authenticators
:
-
lexik_jwt_authentication.jwt_token_authenticator
json_login
:
check_path
:
/api/_jwt
username_path
:
usernameOrEmail
password_path
:
password
success_handler
:
lexik_jwt_authentication.handler.authentication_success
failure_handler
:
lexik_jwt_authentication.handler.authentication_failure
main
:
anonymous
:
true
http_basic
:
realm
:
"
Limaju's
Authentication
Desk"
# activate different ways to authenticate
# https://symfony.com/doc/current/security.html#firewalls-authentication
...
...
config/routes/jwt.yaml
View file @
c690d912
authentication_token
:
path
:
/api/
authentication_token
path
:
/api/
_jwt
methods
:
[
'
POST'
]
\ No newline at end of file
config/services.yaml
View file @
c690d912
...
...
@@ -56,4 +56,10 @@ services:
App\Swagger\JwtDecorator
:
decorates
:
'
api_platform.swagger.normalizer.documentation'
arguments
:
[
'
@App\Swagger\JwtDecorator.inner'
]
autoconfigure
:
false
\ No newline at end of file
autoconfigure
:
false
app.event.jwt_created_listener
:
class
:
App\EventListener\JWTCreatedListener
arguments
:
[
'
@request_stack'
]
tags
:
-
{
name
:
kernel.event_listener
,
event
:
lexik_jwt_authentication.on_jwt_created
,
method
:
onJWTCreated
}
\ No newline at end of file
src/Entity/User.php
View file @
c690d912
...
...
@@ -100,14 +100,6 @@ class User implements UserInterface
*/
private
$password
;
/**
* @Groups({"User:login"})
* @Assert\NotBlank(groups={"login"})
* @Assert\Length(max=64, groups={"login"})
* @SerializedName("username")
*/
private
$login
;
/**
* @Groups({"User:create", "User:edit"})
* @Assert\NotBlank(groups={"register, login"})
...
...
@@ -135,7 +127,6 @@ class User implements UserInterface
$this
->
uuid
=
Uuid
::
uuid4
();
}
public
function
getId
():
?int
{
return
$this
->
id
;
...
...
@@ -205,17 +196,6 @@ class User implements UserInterface
return
$this
;
}
public
function
getLogin
():
?string
{
return
$this
->
login
;
}
public
function
setLogin
(
$login
):
self
{
$this
->
login
=
$login
;
return
this
;
}
public
function
getPlainPassword
():
string
{
return
$this
->
plainPassword
;
...
...
src/EventListener/JWTCreatedListener.php
0 → 100644
View file @
c690d912
<?php
namespace
App\EventListener
;
use
Lexik\Bundle\JWTAuthenticationBundle\Event\JWTCreatedEvent
;
use
Symfony\Component\HttpFoundation\RequestStack
;
class
JWTCreatedListener
{
/**
* @var RequestStack
*/
private
$requestStack
;
/**
* @param RequestStack $requestStack
*/
public
function
__construct
(
RequestStack
$requestStack
)
{
$this
->
requestStack
=
$requestStack
;
}
/**
* @param JWTCreatedEvent $event
*
* @return void
*/
public
function
onJWTCreated
(
JWTCreatedEvent
$event
)
{
$request
=
$this
->
requestStack
->
getCurrentRequest
();
$payload
=
$event
->
getData
();
/** @var User $user */
$user
=
$event
->
getUser
();
$payload
[
'uuid'
]
=
$user
->
getUuid
();
unset
(
$payload
[
'username'
]);
$event
->
setData
(
$payload
);
}
}
\ No newline at end of file
src/Repository/UserRepository.php
View file @
c690d912
...
...
@@ -26,7 +26,7 @@ class UserRepository extends ServiceEntityRepository implements UserLoaderInterf
public
function
loadUserByUsername
(
$usernameOrEmail
)
{
return
$this
->
createQueryBuilder
(
'u'
)
->
where
(
'u.username = :query or u.email = :query'
)
->
where
(
'u.username = :query or u.email =
:query or u.uuid =
:query'
)
->
setParameter
(
'query'
,
$usernameOrEmail
)
->
getQuery
()
->
getOneOrNullResult
();
...
...
src/Swagger/JwtDecorator.php
View file @
c690d912
...
...
@@ -38,7 +38,7 @@ final class JwtDecorator implements NormalizerInterface
$docs
[
'components'
][
'schemas'
][
'Credentials'
]
=
[
'type'
=>
'object'
,
'properties'
=>
[
'username'
=>
[
'username
OrEmail
'
=>
[
'type'
=>
'string'
,
'example'
=>
'api'
,
],
...
...
@@ -51,7 +51,7 @@ final class JwtDecorator implements NormalizerInterface
$tokenDocumentation
=
[
'paths'
=>
[
'/api/
authentication_token
'
=>
[
'/api/
_jwt
'
=>
[
'post'
=>
[
'tags'
=>
[
'Token'
],
'operationId'
=>
'postCredentialsItem'
,
...
...
@@ -78,7 +78,6 @@ final class JwtDecorator implements NormalizerInterface
],
],
];
dump
(
array_merge_recursive
(
$docs
,
$tokenDocumentation
));
return
array_merge_recursive
(
$docs
,
$tokenDocumentation
);
}
}
\ No newline at end of file
Write
Preview
Supports
Markdown
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