Skip to content

Commit 2b45351

Browse files
committed
allow for a custom implementation of the token generator
ResetPasswordTokenComponents is internal, consumers now can create their own implementation of the ResetPasswordTokenGenerator without having to use our internal token components class.
1 parent a69df43 commit 2b45351

4 files changed

+36
-4
lines changed

src/Generator/ResetPasswordTokenGenerator.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use SymfonyCasts\Bundle\ResetPassword\Exception\ResetPasswordRuntimeException;
1313
use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordTokenComponents;
14+
use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordTokenComponentsInterface;
1415

1516
/**
1617
* @author Jesse Rushlow <[email protected]>
@@ -37,7 +38,7 @@ public function __construct(
3738
*
3839
* @throws ResetPasswordRuntimeException
3940
*/
40-
public function createToken(\DateTimeInterface $expiresAt, int|string $userId, ?string $verifier = null): ResetPasswordTokenComponents
41+
public function createToken(\DateTimeInterface $expiresAt, int|string $userId, ?string $verifier = null): ResetPasswordTokenComponentsInterface
4142
{
4243
if (null === $verifier) {
4344
$verifier = $this->generator->getRandomAlphaNumStr();

src/Generator/ResetPasswordTokenGeneratorInterface.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99

1010
namespace SymfonyCasts\Bundle\ResetPassword\Generator;
1111

12-
use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordTokenComponents;
12+
use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordTokenComponentsInterface;
1313

1414
/**
1515
* @author Jesse Rushlow <[email protected]>
1616
*/
1717
interface ResetPasswordTokenGeneratorInterface
1818
{
19-
public function createToken(\DateTimeInterface $expiresAt, int|string $userId, ?string $verifier = null): ResetPasswordTokenComponents;
19+
public function createToken(\DateTimeInterface $expiresAt, int|string $userId, ?string $verifier = null): ResetPasswordTokenComponentsInterface;
2020
}

src/Model/ResetPasswordTokenComponents.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
* @internal
1717
*/
18-
final class ResetPasswordTokenComponents
18+
final class ResetPasswordTokenComponents implements ResetPasswordTokenComponentsInterface
1919
{
2020
public function __construct(
2121
private string $selector,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the SymfonyCasts ResetPasswordBundle package.
5+
* Copyright (c) SymfonyCasts <https://symfonycasts.com/>
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
namespace SymfonyCasts\Bundle\ResetPassword\Model;
11+
12+
/**
13+
* @author Jesse Rushlow <[email protected]>
14+
*/
15+
interface ResetPasswordTokenComponentsInterface
16+
{
17+
/**
18+
* @return string Non-hashed random string used to fetch request objects from persistence
19+
*/
20+
public function getSelector(): string;
21+
22+
/**
23+
* @return string The hashed non-public token used to validate reset password requests
24+
*/
25+
public function getHashedToken(): string;
26+
27+
/**
28+
* The public token consists of a concatenated random non-hashed selector string and random non-hashed verifier string.
29+
*/
30+
public function getPublicToken(): string;
31+
}

0 commit comments

Comments
 (0)