Payum icon indicating copy to clipboard operation
Payum copied to clipboard

Track token usage and automatic token invalidation

Open backbone87 opened this issue 11 years ago • 5 comments

Proposed Changes:

  • add a usage (integer, not null) and maxUsage (integer, null) fields to TokenInterface
  • each call to verify of TokenVerifier should increment the usage field
  • each call to verify should check if maxUsage is set (not null) and if usage >= maxUsage, it should automatically invalidate the token

These changes remove some boilerplate code in token handling applications (for example in the controllers in the payum bundle)

backbone87 avatar Nov 28 '14 15:11 backbone87

if you want i can provide a PR

backbone87 avatar Nov 28 '14 16:11 backbone87

I'd :+1: in general, I was also thinking of expiration https://github.com/Payum/Payum/issues/76.

I am not sure about maxUsage. How sets this field, the token factory? but it may vary.

makasim avatar Nov 29 '14 10:11 makasim

These changes remove some boilerplate code in token handling applications (for example in the controllers in the payum bundle)

could you clarify it a bit more?

makasim avatar Nov 29 '14 10:11 makasim

Kind of Offtopic: I am also think that when we call invalidate($token) it must not be delete, just marked as invalid or used, so we can revert the change.

for example when I debug application I need to call capture url several times but the token can be deleted, so I have to start from the very beginning or comment out the invalidate method call.

makasim avatar Nov 29 '14 10:11 makasim

The TokenFactory can get an additional optional parameter: createToken(..., $maxUsage = null); The createCaptureToken et al of the generic interface can use sensible default values (which means $maxUsage=null for notify and $maxUsage=1 for the rest)

What i mean with boilerplate code: just the need to invalidate the token, which is kind of repeating action for every token verifying action (except notify).

I agree with the invalid flag.

Another idea: store token creation date and max age date. It gives some more security to token validity (unused tokens are not valid forever) and helps to clean the token table of old tokens; something like: DELETE FROM token_table WHERE NOW() > max_age + '1 month' OR (invalid = 1 AND NOW() > creation_date + '1 month')

backbone87 avatar Nov 29 '14 12:11 backbone87