• Shopping Cart Shopping Cart
    0Shopping Cart
London App Developer
  • Courses
  • Consulting
  • Tutorials
  • About
  • Click to open the search input field Click to open the search input field Search
  • Menu Menu
Django REST Framework

JSON Web Tokens vs Token Authentication

What is the difference between JSON web wokens (JWT) and token authentication? We get this question a lot in our Build a REST API Beginner and Advanced courses.

JSON web tokens (JWT) and token auth are two different types of authentication.

Token Authentication

Token authentication, or sometimes referred to as token auth, works by generating a random string (a token) for the user when they authenticate. The token is then included in the HTTP auth header on each subsequent request, and then validated by checking the database on each request.

The benefit of the token auth is that it’s the simplest form of authentication that keeps the user’s credentials secure (because the token is sent with each request instead of a username and password). This way the users credentials (username/password) is only sent to the server once and never stored/cached for future requests, which keeps their details secure.

Tokens can also be revoked if desired to force users to re-authenticate.

The downside of token auth is that the database is hit at least once for every request. This is fine for small to medium scale apps, but may be an issue if you have to handle large volumes (100k+) requests in a short space of time, because of the sheer number of database requests required.

JSON Web Tokens (JWT)

JWT is a different approach which uses encryption and hashing techniques to validate the token instead of database checks. It starts the same as token auth, by sending the username and password and validating it against the database.

Once validated, the server generates a token based on a secret key which only the server knows. The client can then include this token in the HTTP headers of subsequent requests, and the server can validate it using the secret key without hitting the database.

The token usually converts to a JSON object with the details about the authenticating user (typically a user ID) so the server knows which user is authenticating without accessing the database at all.

Each token is valid for a fixed period of time, after which the server must use a refresh token to request a new one. This allows the server to block access to clients if required.

The benefit of JWT is that it is more scalable, because it requires less database hits. The downside is that it’s more complicated to implement.

To summarise, token authentication is great if you are looking for a simple auth system which is easy to implement and maintain. However, you might want to consider investing the extra time to implement JWT if you anticipate lots of traffic to your API.

I hope you found this post useful. If you are interested in learning how to build APIs using token authentication, check out our courses below:

  • Build a Backend REST API with Python & Django - Advanced
    Build a Backend REST API with Python & Django – Advanced
    Buy on Udemy
  • Build a Backend REST API with Python & Django - Beginner
    Build a Backend REST API with Python & Django – Beginner
    Enrol Now
Tags: JSON web tokens, JWT, token auth, token authentication
Share this entry
  • Share on Facebook
  • Share on X
  • Share on WhatsApp
  • Share on Pinterest
  • Share on LinkedIn
  • Share on Tumblr
  • Share on Vk
  • Share on Reddit
  • Share by Mail
https://i0.wp.com/londonappdeveloper.com/wp-content/uploads/2020/07/pyenv-1.png?fit=277%2C223&ssl=1 223 277 mark https://londonappdeveloper.com/wp-content/uploads/2018/12/lon_website_logo-300x110.png mark2020-07-08 20:50:072020-07-08 20:58:57JSON Web Tokens vs Token Authentication
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Pages

  • About
  • Consulting
  • Home
  • Tutorials

Categories

  • AI
  • Android
  • Android Studio
  • Angular
  • Aptana Studio
  • AWS
  • Bootstrap
  • Career advice
  • Celery
  • Databases
  • Deployment
  • DevOps
  • Django
  • Django REST Framework
  • Docker
  • Eclipse
  • Getting Help
  • Git
  • Git Bash
  • Git Flow
  • GitHub Actions
  • Google App Engine
  • IDE
  • Ionic Framework
  • iOS
  • JavaScript
  • Job Search
  • Links
  • Linux
  • Mac OS X
  • macOS
  • Node.JS
  • OpenAI
  • PGAdmin
  • Postgres
  • Productivity
  • Python
  • React
  • Salt Stack
  • Stack Overflow
  • Tools
  • Travis-CI
  • Tutorials
  • Ubuntu
  • Uncategorized
  • Vagrant
  • VSCode
  • WebSockets
  • Windows 10
  • WordPress

London App Developer Ltd,

71-75 Shelton Street, Covent Garden, London, United Kingdom, WC2H 9JQ

Company registration number: 09718346

© London App Developer - London App Developer Ltd, Company Registration Number: 09718346, VAT: GB224061842
  • Link to X
  • Link to Youtube
  • Link to Facebook
  • Link to Reddit
Link to: Traditional vs Single Page websites and which language to learn Link to: Traditional vs Single Page websites and which language to learn Traditional vs Single Page websites and which language to learnTraditional vs Single Page websites Link to: How do you debug a Django application that is running in Docker? Link to: How do you debug a Django application that is running in Docker? django and docker logos with a picture of a spiderHow do you debug a Django application that is running in Docker?
Scroll to top Scroll to top Scroll to top

This site uses cookies. By continuing to browse the site, you are agreeing to our use of cookies.

OKLearn more

Cookie and Privacy Settings



How we use cookies

We may request cookies to be set on your device. We use cookies to let us know when you visit our websites, how you interact with us, to enrich your user experience, and to customize your relationship with our website.

Click on the different category headings to find out more. You can also change some of your preferences. Note that blocking some types of cookies may impact your experience on our websites and the services we are able to offer.

Essential Website Cookies

These cookies are strictly necessary to provide you with services available through our website and to use some of its features.

Because these cookies are strictly necessary to deliver the website, refusing them will have impact how our site functions. You always can block or delete cookies by changing your browser settings and force blocking all cookies on this website. But this will always prompt you to accept/refuse cookies when revisiting our site.

We fully respect if you want to refuse cookies but to avoid asking you again and again kindly allow us to store a cookie for that. You are free to opt out any time or opt in for other cookies to get a better experience. If you refuse cookies we will remove all set cookies in our domain.

We provide you with a list of stored cookies on your computer in our domain so you can check what we stored. Due to security reasons we are not able to show or modify cookies from other domains. You can check these in your browser security settings.

Google Analytics Cookies

These cookies collect information that is used either in aggregate form to help us understand how our website is being used or how effective our marketing campaigns are, or to help us customize our website and application for you in order to enhance your experience.

If you do not want that we track your visit to our site you can disable tracking in your browser here:

Other external services

We also use different external services like Google Webfonts, Google Maps, and external Video providers. Since these providers may collect personal data like your IP address we allow you to block them here. Please be aware that this might heavily reduce the functionality and appearance of our site. Changes will take effect once you reload the page.

Google Webfont Settings:

Google Map Settings:

Google reCaptcha Settings:

Vimeo and Youtube video embeds:

Other cookies

The following cookies are also needed - You can choose if you want to allow them:

Privacy Policy

You can read about our cookies and privacy settings in detail on our Privacy Policy Page.

Privacy Policy
Accept settingsHide notification only