Wednesday, 1 August 2018

How to authenticate/authorize anonymous user for a limited time?

After a user confirms that he owns a phone number I want to give him an access to some resource for a limited amount of time. How would you solve this problem?

My first idea:

  1. Anonymous user enters protected route.
  2. I send him an sms with confirmation code to the phone number related to the resource under given route.
  3. User confirms his identity.
  4. I generate a JWT token with sub containing given phone number and I set exp for 5 minutes.
  5. I push this JWT token into session.
  6. I use voter on my protected route to check if token is present && hasn't expired && sub === phone number related to resource.

My second idea: 1, 2 and 3 are same as above.

  1. When user confirms code that was sent to him the newly created VerificationCodeListener issues a token.
  2. The token is stored inside token storage. The user inside the token is an anonymous user containing just a phone.
  3. Inside my voter I check if phones match (the one from token and phone related to resource).

Is there any better way to do this? I don't know Symfony inside out.



from How to authenticate/authorize anonymous user for a limited time?

No comments:

Post a Comment