Skip to content

Commit

Permalink
allow for a custom implementation of the token generator
Browse files Browse the repository at this point in the history
ResetPasswordTokenComponents is internal, consumers now can
create their own implementation of the ResetPasswordTokenGenerator
without having to use our internal token components class.
  • Loading branch information
jrushlow committed Jun 14, 2024
1 parent c656d65 commit bb10243
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/Generator/ResetPasswordTokenGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use SymfonyCasts\Bundle\ResetPassword\Exception\ResetPasswordRuntimeException;
use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordTokenComponents;
use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordTokenComponentsInterface;

/**
* @author Jesse Rushlow <[email protected]>
Expand Down Expand Up @@ -38,7 +39,7 @@ public function __construct(
*
* @throws ResetPasswordRuntimeException
*/
public function createToken(\DateTimeInterface $expiresAt, int|string $userId, ?string $verifier = null): ResetPasswordTokenComponents
public function createToken(\DateTimeInterface $expiresAt, int|string $userId, ?string $verifier = null): ResetPasswordTokenComponentsInterface
{
if (null === $verifier) {
$verifier = $this->generator->getRandomAlphaNumStr();
Expand Down
4 changes: 2 additions & 2 deletions src/Generator/ResetPasswordTokenGeneratorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

namespace SymfonyCasts\Bundle\ResetPassword\Generator;

use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordTokenComponents;
use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordTokenComponentsInterface;

/**
* @author Jesse Rushlow <[email protected]>
*/
interface ResetPasswordTokenGeneratorInterface
{
public function createToken(\DateTimeInterface $expiresAt, int|string $userId, ?string $verifier = null): ResetPasswordTokenComponents;
public function createToken(\DateTimeInterface $expiresAt, int|string $userId, ?string $verifier = null): ResetPasswordTokenComponentsInterface;
}
2 changes: 1 addition & 1 deletion src/Model/ResetPasswordTokenComponents.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* @internal
*/
final class ResetPasswordTokenComponents
final class ResetPasswordTokenComponents implements ResetPasswordTokenComponentsInterface
{
public function __construct(
#[\SensitiveParameter]
Expand Down
31 changes: 31 additions & 0 deletions src/Model/ResetPasswordTokenComponentsInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/*
* This file is part of the SymfonyCasts ResetPasswordBundle package.
* Copyright (c) SymfonyCasts <https://symfonycasts.com/>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace SymfonyCasts\Bundle\ResetPassword\Model;

/**
* @author Jesse Rushlow <[email protected]>
*/
interface ResetPasswordTokenComponentsInterface
{
/**
* @return string Non-hashed random string used to fetch request objects from persistence
*/
public function getSelector(): string;

/**
* @return string The hashed non-public token used to validate reset password requests
*/
public function getHashedToken(): string;

/**
* The public token consists of a concatenated random non-hashed selector string and random non-hashed verifier string.
*/
public function getPublicToken(): string;
}

0 comments on commit bb10243

Please sign in to comment.