Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
setUserLoader example
$passport
=
$event
->
getPassport
(
)
;
if
(
!
$passport
->
hasBadge
(
UserBadge::
class
)
)
{
return
;
}
/** @var UserBadge $badge */
$badge
=
$passport
->
getBadge
(
UserBadge::
class
)
;
if
(
null !==
$badge
->
getUserLoader
(
)
)
{
return
;
}
$badge
->
setUserLoader
(
$this
->userProvider->
loadUserByIdentifier
(
...
)
)
;
}
}
public
function
authenticate
(
Request
$request
)
: Passport
{
$accessToken
=
$this
->accessTokenExtractor->
extractAccessToken
(
$request
)
;
if
(
!
$accessToken
)
{
throw
new
BadCredentialsException
(
'Invalid credentials.'
)
;
}
$userBadge
=
$this
->accessTokenHandler->
getUserBadgeFrom
(
$accessToken
)
;
if
(
$this
->userProvider
&&
(
null ===
$userBadge
->
getUserLoader
(
)
||
$userBadge
->
getUserLoader
(
)
instanceof FallbackUserLoader
)
)
{
$userBadge
->
setUserLoader
(
$this
->userProvider->
loadUserByIdentifier
(
...
)
)
;
}
return
new
SelfValidatingPassport
(
$userBadge
)
;
}
public
function
createToken
(
Passport
$passport
, string
$firewallName
)
: TokenInterface
{
return
new
PostAuthenticationToken
(
$passport
->
getUser
(
)
,
$firewallName
,
$passport
->
getUser
(
)
->
getRoles
(
)
)
;
}
public
function
onAuthenticationSuccess
(
Request
$request
, TokenInterface
$token
, string
$firewallName
)
: ?Response
{