I've got an endpoint for HTTP GET at api/token which requires a username and password, since HTTP GET can't include a JSON body I don't know how a password should be sent. Also once I get the token, how should it be included in API calls? Just another field in JSON or in the header?
-
you may find this interesting: stackoverflow.com/questions/1582894/…, also you can open the browser console and see how each site sends creedentials to the server (for example you may inspect stackoverflow login and discover that the password is beign send hashed from the client)Victor– Victor2020-06-28 13:02:12 +00:00Commented Jun 28, 2020 at 13:02
4 Answers
You shoud leverage the header Authorization which is the common way to provide credentials within a call to a RESTful service.
This link could give you more hints on this: https://templth.wordpress.com/2015/01/05/implementing-authentication-with-tokens-for-restful-applications/.
Hope it helps you, Thierry
Comments
I suggest to use JSON Web Tokens which could be used in a URL, POST parameter, or an HTTP header.
A good article about JWT is this.
1 Comment
There's no true practise but only common practice.
- If possible, switch your route from
GETtoPOSTand send your password in theHTTPBody. If not possible, you'll need to append parameters to the URL. - Once you retrieve an auth token, add a header to each authenticated request with your token as value (eg. "
MyCompany-Auth": "0123456789").
Another good practice is also to use SSL (TLS) over your API calls. You can use a self-signed certificate if you don't want to pay too much.
1 Comment
Authorization header. So he can use Authorization: bearer 0123456789.