Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
fromRawCookie example
public
function
testBase64EncodedTokens
(
)
{
$this
->tokenProvider->
expects
(
$this
->
any
(
)
)
->
method
(
'loadTokenBySeries'
)
->
with
(
'series1'
)
->
willReturn
(
new
PersistentToken
(
InMemoryUser::
class
, 'wouter', 'series1', 'tokenvalue',
new
\
DateTimeImmutable
(
'-10 min'
)
)
)
;
$this
->tokenProvider->
expects
(
$this
->
once
(
)
)
->
method
(
'updateToken'
)
->
with
(
'series1'
)
;
$rememberMeDetails
=
new
RememberMeDetails
(
InMemoryUser::
class
, 'wouter', 360, 'series1:tokenvalue'
)
;
$rememberMeDetails
= RememberMeDetails::
fromRawCookie
(
base64_encode
(
$rememberMeDetails
->
toString
(
)
)
)
;
$this
->handler->
consumeRememberMeCookie
(
$rememberMeDetails
)
;
}
}
// the `null` return value indicates that this authenticator supports lazy firewalls
return
null;
}
public
function
authenticate
(
Request
$request
)
: Passport
{
if
(
!
$rawCookie
=
$request
->cookies->
get
(
$this
->cookieName
)
)
{
throw
new
\
LogicException
(
'No remember-me cookie is found.'
)
;
}
$rememberMeCookie
= RememberMeDetails::
fromRawCookie
(
$rawCookie
)
;
$userBadge
=
new
UserBadge
(
$rememberMeCookie
->
getUserIdentifier
(
)
,
fn
(
)
=>
$this
->rememberMeHandler->
consumeRememberMeCookie
(
$rememberMeCookie
)
)
;
return
new
SelfValidatingPassport
(
$userBadge
)
;
}
public
function
createToken
(
Passport
$passport
, string
$firewallName
)
: TokenInterface
{
return
new
RememberMeToken
(
$passport
->
getUser
(
)
,
$firewallName
,
$this
->secret
)
;
}
public
function
clearRememberMeCookie
(
)
: void
{
parent::
clearRememberMeCookie
(
)
;
$cookie
=
$this
->requestStack->
getMainRequest
(
)
->cookies->
get
(
$this
->options
[
'name'
]
)
;
if
(
null ===
$cookie
)
{
return
;
}
$rememberMeDetails
= RememberMeDetails::
fromRawCookie
(
$cookie
)
;
[
$series
]
=
explode
(
':',
$rememberMeDetails
->
getValue
(
)
)
;
$this
->tokenProvider->
deleteTokenBySeries
(
$series
)
;
}
/** * @internal */
public
function
getTokenProvider
(
)
: TokenProviderInterface
{
return
$this
->tokenProvider;
}
}