Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.x] use UriSigner::checkRequest() to validate signatures using a Request object #157

Merged
merged 12 commits into from
Mar 12, 2024

Conversation

jrushlow
Copy link
Collaborator

@jrushlow jrushlow commented Feb 27, 2024

  • add's a new validateEmailConfirmationFromRequest() to VerifyEmailHelperInterface & it's implementation.
  • deprecates validateEmailConfirmation() in VerifyEmailHelperInterface & it's implementation.
  • deprecates VerifyEmailQueryUtility as this is no longer needed in the new "fromRequest" helper method.
  • does not deprecates the 3rd $queryUtility argument in the VerifyEmailHelper::__construct() method as this argument is not nullable`
  • deprecates passing anything other than an instance of UriSigner as the $uriSigner argument in the VerifyEmailHelper::__construct() method.
  • silences self deprecations (introduced by this PR) in tests using @group legacy annotations. This is basically our entire test suite. Work is already started in WIP ! 2.x ! - remove deprecations from 157 #159 that will remove these annotations and deprecations in 2.0.

Doc's will be updated in #143 after maker-bundle #1464 is updated / merged to reflect the changes in this PR.

fixes #155

@@ -63,21 +64,60 @@ public function generateSignature(string $routeName, string $userId, string $use
return new VerifyEmailSignatureComponents(\DateTimeImmutable::createFromFormat('U', (string) $expiryTimestamp), $signature, $generatedAt);
}

public function validateEmailConfirmation(string $signedUrl, string $userId, string $userEmail): void
public function validateEmailConfirmation(string $signedUrl, string $userId, string $userEmail, ?Request $request = null): void
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'll be better off leaving this method alone and adding a deprecation @trigger_deprecation('Use validateEmailConfirmationFromRequest instead...)

  1. theres alot of if/else action happening in here
  2. we don't have a clean path forward to reorder the arguments where Request is the 1st argument.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so too. Leave this method alone, but deprecate it.

Copy link
Contributor

@weaverryan weaverryan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for getting this going!

@@ -63,21 +64,60 @@ public function generateSignature(string $routeName, string $userId, string $use
return new VerifyEmailSignatureComponents(\DateTimeImmutable::createFromFormat('U', (string) $expiryTimestamp), $signature, $generatedAt);
}

public function validateEmailConfirmation(string $signedUrl, string $userId, string $userEmail): void
public function validateEmailConfirmation(string $signedUrl, string $userId, string $userEmail, ?Request $request = null): void
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so too. Leave this method alone, but deprecate it.

src/VerifyEmailHelper.php Show resolved Hide resolved
@@ -33,6 +36,8 @@ interface VerifyEmailHelperInterface
public function generateSignature(string $routeName, string $userId, string $userEmail, array $extraParams = []): VerifyEmailSignatureComponents;

/**
* @deprecated since v1.17.0, use validateEmailConfirmationFromRequest instead.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this even the right way to deprecate an interface method?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To the best of my knowledge, yes - but not sure.

@jrushlow jrushlow mentioned this pull request Mar 6, 2024
1 task
@jrushlow jrushlow changed the title WIP _ validate using checkRequest() [1.x] use UriSigner::checkRequest() to validate signatures using a Request object Mar 7, 2024
@jrushlow jrushlow added Status: Needs Review Needs to be reviewed and removed Status: Needs Work Additional work is needed labels Mar 7, 2024
@jrushlow jrushlow marked this pull request as ready for review March 7, 2024 13:14
if (!$uriSigner instanceof UriSigner) {
/** @psalm-suppress UndefinedFunction */
@trigger_deprecation('symfonycasts/verify-email-bundle', '1.17.0', 'Not providing an instance of %s is deprecated. It will be required in v2.0', UriSigner::class);
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also deprecated "passing $queryUtility as 3rd argument is deprecated. The arg will be removed in the future..." but usually when we do this - the param is = nullable. We can't do that here because the last 2 arg's are not nullable.

Do we let this ride as is and document this "non-deprecated" change in Upgrade.md or add the deprecation anyway without providing a way for the user to "silence" it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, maybe we lave the argument as is & not deprecated for now. Then we deprecate it in v2, once it's fully unused. There may be a better way to handle this, but I can't see it at the moment.

@@ -23,13 +25,19 @@ class VerifyEmailQueryUtility
{
public function getTokenFromQuery(string $uri): string
{
/** @psalm-suppress UndefinedFunction */
@trigger_deprecation('symfonycasts/verify-email-bundle', '1.17.0', 'This method is deprecated and will be removed in 2.0.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious that this needs the pslam-suppress... since the library does require the deprecations-contract

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya, I don't get it either - locally I don't get the error. But on CI, we do. I think it has something to do with psalm not picking up the autoload.

image

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check into this outside of this PR.

if (!$uriSigner instanceof UriSigner) {
/** @psalm-suppress UndefinedFunction */
@trigger_deprecation('symfonycasts/verify-email-bundle', '1.17.0', 'Not providing an instance of %s is deprecated. It will be required in v2.0', UriSigner::class);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, maybe we lave the argument as is & not deprecated for now. Then we deprecate it in v2, once it's fully unused. There may be a better way to handle this, but I can't see it at the moment.

@@ -33,6 +36,8 @@ interface VerifyEmailHelperInterface
public function generateSignature(string $routeName, string $userId, string $userEmail, array $extraParams = []): VerifyEmailSignatureComponents;

/**
* @deprecated since v1.17.0, use validateEmailConfirmationFromRequest instead.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To the best of my knowledge, yes - but not sure.

src/Util/VerifyEmailQueryUtility.php Outdated Show resolved Hide resolved
@jrushlow jrushlow added the Status: Reviewed Has been reviewed by a maintainer label Mar 12, 2024
@jrushlow jrushlow merged commit d60e9e8 into SymfonyCasts:main Mar 12, 2024
8 checks passed
@jrushlow jrushlow deleted the feature/uri-signer branch March 12, 2024 14:25
@jrushlow jrushlow mentioned this pull request Mar 16, 2024
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New Feature Status: Needs Review Needs to be reviewed Status: Reviewed Has been reviewed by a maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Avoid using Request::getUri()
2 participants