Skip to content

v7.0.0-token-authentication

Choose a tag to compare

@GitauHarrison GitauHarrison released this 16 Oct 07:20
· 4 commits to main since this release

Protect API endpoints as the web client protects select pages from anonymous access.

  • Generate tokens
  • Add token expiration to improve security
  • Revoke the token if needed instead of relying entirely on the expiration time

Basic authentication requires that a client provide a user's username and password in the request. The user's credentials are base64 encoded and the result is added to the Authorization header sent by the client.

The server will then create a token for the selected user. Now, this user can be verified based on their token. A 401 Unauthorized error response will be generated if there is no such user.

To protect endpoints, add token_auth.login_required. The decorator comes from Flask-HTTPAuth.

With the user authenticated and authorized, each protected endpoint can be accessed by adding the selected user's token in the Authorization header as Authorization: Bearer < token >.