Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do accounts-password email tokens ever expire?

For Accounts.forgotPassword() and Accounts.sendVerificationEmail(), a token is generated.

Does that token ever expire?
If so, after what period of time?

like image 681
Artfree Avatar asked Oct 25 '15 20:10

Artfree


People also ask

How long is a password reset token valid?

By default, password reset tokens expire after one hour. You may change this via the password reset expire option in your config/auth. php file. The default expire is 60 minutes.

Should password reset links expire?

Well-engineered password reset processes will automatically expire or invalidate the password reset URL after a period of time. In some cases, the expiration window may be aggressive, and it's possible the link will expire before the recipient has an opportunity to check their email and reset their password.

What does it mean token expired?

If you experience an error message that states "Token Expired", this is letting you know the system has timed out and will need to be refreshed.


2 Answers

At the moment there is no built-in code that relates to token expiration, neither setting an expiration time nor enforcing it.

The email reset data (token, email and token creation date) is saved in the user's record, as can be seen in the source:

var tokenRecord = {
  token: token,
  email: email,
  when: when
};
Meteor.users.update(userId, {$set: {
  "services.password.reset": tokenRecord
}});

Therefore, the date is in the following mongo selector:

'services.password.reset.when'

Unfortunately, all of the reset data is unset as soon as the resetPassword method is called with the correct token.

This makes it unavailable to the validateLoginAttempt callbacks:

Accounts.validateLoginAttempt(function(options) {
  if (options.methodName === 'resetPassword' && options.allowed === true) {
    console.log('resetPassword', options.user.services.password.reset); //undefined
  }
  return true;
});

Similarly, the email verification token is stored in user.services.email.verificationTokens, which (if set) is an array of token records.

The dates are, therefore, in

'services.email.verificationTokens.when'

You could, however, invalidate old tokens periodically quite easily with this info, or roll your own local fork or wrap of accounts-password.

like image 183
MasterAM Avatar answered Sep 17 '22 15:09

MasterAM


With the current version of Meteor (1.9), tokens do expire, as you can see here in the code (and I guess it has been the case for quite a long time).

Reset password tokens expire after 3 days, when enroll tokens expire after 30 days

These two parameters are configurable using :

Accounts.config({
    passwordResetTokenExpirationInDays : 10,
    passwordEnrollTokenExpirationInDays : 60,
})
like image 30
Victor Avatar answered Sep 21 '22 15:09

Victor