Class OneTimeTokenService
java.lang.Object
com.codename1.backend.security.mail.OneTimeTokenService
Gives out tokens that work once: what a mailed link carries.
String token = tokens.create("invite", "ada@example.com", 3600);
// ... later, from the link
String username = tokens.consume("invite", token); // null unless it is good
A token is 256 random bits, written in 43 characters that need no escaping in a URL. It is for one purpose and one user, stops working at its expiry and when it is used, and is replaced when the same user is given another for the same purpose. Only its SHA-256 is kept: whoever reads the table learns no token, and a token is looked up by that hash, so how long a lookup takes says nothing about a token that was guessed nearly right.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionThe clock expiry is measured by; a test sets its own.Usestokenup and answers the user it was given to, or null when it is not a token forpurpose, has expired or was already used.A new token forusername, good forvaliditySecondsand forpurposealone.voidStops whatever tokenusernameholds forpurposefrom working.
-
Constructor Details
-
OneTimeTokenService
-
-
Method Details
-
clock
The clock expiry is measured by; a test sets its own. -
create
-
consume
-
revoke
-