Reputation: 33608
I confused with basic http authorization. It is needed to send every request to server with Authorization
header or just first one and after that browser rember auth tokens like session id?
Upvotes: 4
Views: 3449
Reputation: 23496
Using basic authentication, every request needs to have an Authorization
HTTP header in the format:
Authorization: Basic <base64(username:password)>
where the username and password are concatenated using a colon (':') and the resulting string is base64 encoded.
If the Authorization header is not part of the request, or the credentials inside are not valid, the server should respond with an HTTP 401 Unauthorized response and include a HTTP header like:
WWW-Authenticate: Basic realm="myRealm"
Basic authentication is an implicit authentication scheme, so after the user enters valid credential, the browser will send them along with each page request.
For AJAX requests you'll need to attach this header from code. However, you really should not use basic authentication to protect an API, for a number of reasons:
Better alternatives to protect web APIs are token based authentication schemes like OAuth2 or HMAC based authentication schemes like Hawk or AWS
Upvotes: 2
Reputation: 4459
Ya that's correct , so for first time when user logs in , his credentials are verified against some data , if correct , a auth token is generated.
Auth token is pretty much a self contained entity (which stores some data signed with a key)
this token gets stores at client side(usually along with a refresh token) for all subsequent requests , this token is kept in Authorization header(Bearer+token)
When server receives this token , it decrypts it with the key , which it used earlier to sign that token. And uses that stored data
If that auth token is expired , refresh token comes into play.
some links to begin with On a high level, how does OAuth 2 work? and jwt.io to get the feel of tokens
Upvotes: 0
Reputation: 66
You have to send the Authorization header on each request. But for example Chrome remembers the auth tokens and sends it automatically on each request.
Upvotes: 2