GeekCoding101 make your way to geek

Authentication Tutorials: Passwords, HTTP Basic Auth and JWT

3 posts on authentication, newest first.

3posts
2023first post

This page collects GeekCoding101’s hands-on authentication tutorials: password login, HTTP Basic Authentication and JWT, each built from scratch in Node.js. If you’re new to the topic, read them in that order, from the simplest scheme to the most flexible.

The posts belong to the Auth101 series. They are free to read, with no sign-up.

Where to start

  1. Password Authentication in Node.js: A Step-by-Step Guide. This covers the most common way to verify a user: a username and password checked by your server. Start here if you’ve never built a login flow.
  2. HTTP Basic Authentication Explained (RFC 7617). This post covers:
    • how the Authorization header carries a Base64-encoded username:password
    • why Basic Auth must run over HTTPS
    • a Node.js and TypeScript middleware you can drop into a project
  3. Unlocking Web Security: Master JWT Authentication. This post covers JWT claims, token structure and signing algorithms. It then builds JWT authentication from scratch in Node.js, with complete, runnable example code.

The three methods at a glance

MethodWhat the client sendsWhat the server checksTypical fit
Password loginUsername and password, usually once through a login formThe password against a stored (hashed) value, then issues a session or tokenUser-facing sign-in
HTTP Basic AuthAuthorization: Basic <base64(username:password)> on every requestThe decoded credentials, on every requestInternal tools and simple APIs, over HTTPS only
JWTAuthorization: Bearer <token>The token’s signature and claims, such as expiryStateless APIs and service-to-service calls

All authentication posts

Authentication vs. authorization

Authentication answers who are you? Authorization answers what are you allowed to do?

Every post on this page is about the first question: proving identity with a password, credentials in a header, or a signed token. Deciding what a verified user may access is a separate step that comes after.

FAQ

Is HTTP Basic Authentication secure? Only over HTTPS. Base64 is an encoding, not encryption, so anyone who can read the request can decode the username and password. The credentials are also sent with every request, so plain HTTP exposes them every time.

Should I use JWT or server-side sessions? It depends on where you want state to live:

  • Sessions keep state on the server. They are easy to revoke but need shared storage when you run several servers.
  • JWTs carry signed claims in the token itself. The server can verify them without a lookup, but tokens are harder to revoke before they expire.

The JWT post explains the token structure so you can judge the trade-off.

What’s the difference between JWT and Basic Auth? With Basic Auth, the client sends the real username and password on every request. With JWT, the client signs in once, then sends a signed token that the server verifies instead of re-checking the password.

Do I need to know Node.js to follow along? The examples are written in Node.js, and the Basic Auth post also includes a TypeScript middleware. Basic JavaScript is enough to follow the code. The concepts (headers, encoding, signatures, claims) apply in any language.