Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
issuedAt example
$expires
=
$expires
->
modify
(
sprintf
(
'+%d seconds',
$tokenStruct
->
getExpires
(
)
)
)
;
}
else
{
$expires
=
$expires
->
modify
(
sprintf
(
'-%d seconds',
abs
(
$tokenStruct
->
getExpires
(
)
)
)
)
;
}
$jwtToken
=
$this
->configuration->
builder
(
)
->
identifiedBy
(
Uuid::
randomHex
(
)
)
->
issuedAt
(
new
\
DateTimeImmutable
(
'@' .
time
(
)
)
)
->
canOnlyBeUsedAfter
(
new
\
DateTimeImmutable
(
'@' .
time
(
)
)
)
->
expiresAt
(
$expires
)
->
relatedTo
(
$tokenStruct
->
getTransactionId
(
)
?? ''
)
->
withClaim
(
'pmi',
$tokenStruct
->
getPaymentMethodId
(
)
)
->
withClaim
(
'ful',
$tokenStruct
->
getFinishUrl
(
)
)
->
withClaim
(
'eul',
$tokenStruct
->
getErrorUrl
(
)
)
->
getToken
(
$this
->configuration->
signer
(
)
,
$this
->configuration->
signingKey
(
)
)
;
$this
->
write
(
$jwtToken
->
toString
(
)
,
$expires
)
;
return
$jwtToken
->
toString
(
)
;
}
$configuration
= Configuration::
forSymmetricSigner
(
new
Sha256
(
)
,
$key
)
;
$expiration
=
new
\
DateTimeImmutable
(
'+10 minutes'
)
;
$shopId
=
$this
->shopIdProvider->
getShopId
(
)
;
$builder
=
$configuration
->
builder
(
)
->
issuedBy
(
$shopId
)
->
issuedAt
(
new
\
DateTimeImmutable
(
)
)
->
canOnlyBeUsedAfter
(
new
\
DateTimeImmutable
(
)
)
->
expiresAt
(
$expiration
)
;
if
(
\
in_array
(
'sales_channel:read',
$privileges
, true
)
)
{
$builder
->
withClaim
(
'salesChannelId',
$context
->
getSalesChannel
(
)
->
getId
(
)
)
;
}
if
(
\
in_array
(
'customer:read',
$privileges
, true
)
)
{
$builder
->
withClaim
(
'customerId',
$context
->
getCustomer
(
)
->
getId
(
)
)
;
}