dewastator
dewastator

Reputation: 213

Token authentication in SPA app

I started new project. It is small application (playground) to learn couple new concepts. I will create backend API using Ruby on Rails and Single Page Application using React. I stuck in Authentication. I would like to create custom Token-based Authorization/Authorization. I came to following auth flow:

  1. User fill password/login and send to backed using Ajax and through secured HTTPS connection.
  2. Backed checks if user exist in DB. If user exist backend create Token and save to Redis with user id.
  3. Backend response with token to client app.
  4. On client side I will save above token to local storage.
  5. Before every request I will get token from locale storage and pass to request header.
  6. On backend I will take token from header and check if exist in Redis db.

Is this flow correct? Should I decrypt token on client side or It is not necessary? This project is only playground but I would like to do It properly. Please give me some comments if above flow isn't good enough.

Upvotes: 1

Views: 849

Answers (1)

Thierry Templier
Thierry Templier

Reputation: 202156

I think that you have the right approach. This link could give you more details about token-based authentication:

Hope it helps you, Thierry

Upvotes: 1

Related Questions