Staying Signed In

Staying Signed In: Tokens: Signing In with a JWT, Sessions and Cookies, and When They Fit Better.

Updated

  1. Tokens: Signing In with a JWT (Journeyman): After a sign-in, an API hands out a JWT, a signed token in three parts that PyJWT makes with jwt.encode and an exp claim and checks with jwt.decode, at POST /auth/token with the OAuth2 password form so the docs page's Authorize button works, and the caller sends it back in an Authorization header with every request.
  2. Sessions and Cookies, and When They Fit Better (Journeyman): A session signs a user in with a random id from secrets.token_urlsafe, kept in a sessions table and sent in an HttpOnly, Secure, SameSite cookie, so signing out deletes a row and takes effect at once, which suits one website on one server better than a token that stays valid until it expires.