/auth/login ⇒
POST
This API is used to authenticate Your application server API's by assigning the access token to the user.
Returns: Returns the access token & refresh token (JWT).
| Param | Type | Description |
|---|---|---|
| username | string | getting the username from request body. |
| password | string | getting the password from request body. |
Sample code to generate jwt token using nodejs technology.
const jwt = require('jsonwebtoken');
const payload = {
username: username, // Get this from request body
userId: user.id, // Fetched the user from DB and assigned the id
}
const token = jwt.sign(
payload,
secret,
{ expiresIn: `${expiryTime}s`}
);
Example
{
"error": null,
"data": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluQHNwcmluZ2N0LmNvbSIsInVzZXJJZCI6MSwiaWF0IjoxNzE3Njc0NzgwLCJleHAiOjE3MTgyNzk1ODB9.ouElHy3ls4Y409f69dLAtaAn0mrohpkOiff68owEkjU"
}
Error Codes:
400 : Bad Request (If invalid or null body params are passed)
{
"data": null,
"error": {
"code": 400,
"message": "Invalid body in request."
}
}
404 : Not Found (If invalid url or wrong http method is used)
{
"error": {
"code": 404,
"message": "Not found"
},
"data": null
}
500 : Internal Server Error (If there is any exception on server side)
{
"error": {
"code": 500,
"message": "Internal server error"
},
"data": null
}