CsrfTokenGenerator
class CsrfTokenGenerator (View source)
Generates and validates CSRF tokens.
Properties
| protected PrivateKey | $privateKey | The private key service. |
|
| protected MetadataBag | $sessionMetadata | The session metadata bag. |
Methods
Generates a token based on $value, the user session, and the private key.
Validates a token based on $value, the user session, and the private key.
Generates a token based on $value, the token seed, and the private key.
Details
__construct(PrivateKey $private_key, MetadataBag $session_metadata)
Constructs the token generator.
string
get(string $value = '')
Generates a token based on $value, the user session, and the private key.
The generated token is based on the session of the current user. Normally, anonymous users do not have a session, so the generated token will be different on every page request. To generate a token for users without a session, manually start a session prior to calling this function.
bool
validate(string $token, string $value = '')
Validates a token based on $value, the user session, and the private key.
protected string
computeToken(string $seed, string $value = '')
Generates a token based on $value, the token seed, and the private key.