Authentication - Token
Table of Contents
About
A token is a authentication material
Token-based authentication is implemented by:
- generating a token when the user authenticates
- and then setting that token in the Authorization header of each subsequent request to an API.
They carry just enough information to either:
- authorize the user to perform an action,
- or allow a client to get additional information about the authorization process (to then complete it).
The concept behind using tokens is that you can authenticate to a central authority and then have permissions granted to a separate system without needing to give that system your credentials.
If the server providing the service was compromised, credentials would still be safe, and the attacker would only have access to resources until the token expired. Hence tokens are generally short lived.
Articles Related
Benefits
- Unique – tokens are specific and can be generated per use or per device
- Revocable – tokens can can be individually revoked at any time without needing to update unaffected credentials
- Limited – tokens can be narrowly scoped to allow only the access necessary for the use case
- Random – tokens are not subject to the types of dictionary or brute force attempts that simpler passwords that you need to remember or enter regularly might be
Security Consideration
- You should give tokens an expiration because technically, once a token is signed, it is valid forever unless the signing key is changed.
- Do not send tokens over non-HTTPS connections
- Do not add sensitive / privacy data to the payload
Usage
Format
Token type | Language | Size | Signature |
---|---|---|---|
Authentication - Jwt (Json web token) - JSON Web Tokens (JWT) | Json | Low | public/private key |
Simple Web Tokens (SWT) | Only symmetric | ||
Security Assertion Markup Language Tokens (SAML) | Xml | High | public/private key |