Академический Документы
Профессиональный Документы
Культура Документы
Terms:
1. CLIENT_KEY
Key(Similar to username) Given for REST client (react js) to connect with Server
2. CLIENT_SECRET
Secret (similar to password) to be used with key to connect with Server.
3. USER_CREDENTIALS
Username and password entered by User on login screen
4. ACCESS_TOKEN
Token obtained from Server using User Credentials. Server will identify the User based with
this Token. Typically expires in 1 hour.
5. REFRESH_TOKEN
This token will be obtained along with Access Token. It will have longer expiry time than
Access Token. Typically 24 hours. If Access Token is expired, a new token can be obtained from
server using this Refresh token.
6. BASE64_CLIENT_CREDENTIALS
encode CLIENT_KEY and CLIENT_SECRET separated by colon (:) with Base64
Example: If client key is “123456” and client secret is “abcdef” then base Base64 encoded
value of “123456:abcdef” is “MTIzNDU2OmFiY2RlZg==”.
7. BASE_URL
https://example.com
8. Test Credentials
CLIENT_KEY: live-test
CLIENT_SECRET: asdfasdfasdfasdfasdfasdf
Notes:
1. If any API returns status code 5XX (500, 503 etc) then it is server faultAPIs:
2. If any API returns status code 4XX (400, 401, 403 etc) then there is an issue in request.
Reasons can be Invalid url (404), Unauthorized(401), Invalid data (400).
1. Security APIs:
1.1. Signup
password* String
Request
POST /api/signup
Headers:
Content-Type: application/json
{
"username": "example",
"email": "user@example.com",
"password" : "123456",
"confirm_password": "123456"
}
Response
201 If Signup success. An email with verification code will be sent to user
Request
PUT /api/verify-email?token=TOKEN_SENT_ON_MAIL
Response
200 Token verified successfully (No response JSON will be returned. Status code is enough)
400 Invalid token (No response JSON will be returned. Status code is enough)
1.3. Login
Save the ACCESS_TOKEN and REFRESH_TOKEN obtained from successful login to access any
data from server.
Request
POST /oauth/token
Headers:
Content-Type: application/x-www-form-urlencoded
Authorization: Basic BASE64_CLIENT_CREDENTIALS
Form Data:
"Key":"grant_type", "value":"password"
"Key":"client_id", "value":"CLIENT_ID"
"Key":"username", "value":"USER_CREDENTIALS.USERNAME"
"Key":"password", "value":"USER_CREDENTIALS.PASSWORD"
Response
200 Returns ACCESS_TOKEN and REFRESH_TOKEN as below
{
"a ccess_token" :
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MDMyNTI1MjUsInVzZXJfbmFtZSI6ImlicmFo
aW0uYXduQGdtYWlsLmNvbSIsImF1dGhvcml0aWVzIjpbIlJFQURfUFJJVklMRUdFIiwiV1JJVEVfUFJJ
VklMRUdFIl0sImp0aSI6ImE4MWZiYjExLWIxYTEtNDVmNy05ZTdjLTJiOTg5ZTkwMDliNCIsImNsaWV
udF9pZCI6ImxpdmUtdGVzdCIsInNjb3BlIjpbInNnLXNtYXJ0YXBwIl19.MwrPz4hCluQnG4kwLb2_gbZ4
fwk1ltWejQjo3OXavnk",
"t oken_type": "bearer",
"r efresh_token":
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiJpYnJhaGltLmF3bkBnbWFpbC5jb2
0iLCJzY29wZSI6WyJzZy1zbWFydGFwcCJdLCJhdGkiOiJhODFmYmIxMS1iMWExLTQ1ZjctOWU3Yy
0yYjk4OWU5MDA5YjQiLCJleHAiOjE1MDMzMzUzMjUsImF1dGhvcml0aWVzIjpbIlJFQURfUFJJVklM
RUdFIiwiV1JJVEVfUFJJVklMRUdFIl0sImp0aSI6ImNiNmY3NjNlLTdmY2QtNDJjYS04MDVlLTk4ZDR
mNGVjODU0NyIsImNsaWVudF9pZCI6ImxpdmUtdGVzdCJ9.fYXPxABiufiZLVMlTy2U2k5wuPUijrJEf0
efJdT8hkA",
"e xpires_in" : 3599,
"s cope" : "sg-smartapp",
"jti": "a81fbb11-b1a1-45f7-9e7c-2b989e9009b4"
}
400 Invalid USER_CREDENTIALS (Username and password entered by user is invalid)
{
"error": "invalid_grant",
"error_description": "Bad credentials"
}
401 Invalid CLIENT_CREDENTIALS
Request
POST /oauth/token
Headers:
Content-Type: application/x-www-form-urlencoded
Authorization: Basic BASE64_CLIENT_CREDENTIALS
Form Data:
"Key":"grant_type", "value":"refresh_token"
"Key":"refresh_token", "value":"REFRESH_TOKEN"
Response
200 Returns ACCESS_TOKEN and REFRESH_TOKEN as below
{
"access_token":
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MDMyNTM2NTEsInVzZXJfbmFtZSI6Imlicm
FoaW0uYXduQGdtYWlsLmNvbSIsImF1dGhvcml0aWVzIjpbIlJFQURfUFJJVklMRUdFIiwiV1JJVEVfU
FJJVklMRUdFIl0sImp0aSI6Ijc1MzhjZmNjLTk4ZGUtNGNkMi04OGYwLWZjOTMyNWNjNjhkZCIsImNs
aWVudF9pZCI6ImxpdmUtdGVzdCIsInNjb3BlIjpbInNnLXNtYXJ0YXBwIl19.V4TNzj8tp0GKsOd03qoO
E7d-ihkmXmu8qUPcozVr6QQ",
"token_type": "bearer",
"refresh_token":
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiJpYnJhaGltLmF3bkBnbWFpbC5jb2
0iLCJzY29wZSI6WyJzZy1zbWFydGFwcCJdLCJhdGkiOiI3NTM4Y2ZjYy05OGRlLTRjZDItODhmMC1
mYzkzMjVjYzY4ZGQiLCJleHAiOjE1MDMzMzUzMjUsImF1dGhvcml0aWVzIjpbIlJFQURfUFJJVklMRU
dFIiwiV1JJVEVfUFJJVklMRUdFIl0sImp0aSI6ImNiNmY3NjNlLTdmY2QtNDJjYS04MDVlLTk4ZDRmN
GVjODU0NyIsImNsaWVudF9pZCI6ImxpdmUtdGVzdCJ9.sDntmUJH9UEPLJg6ZMQtAnaLI5lxj72QDX
FwurtzWxE",
"expires_in": 3599,
"scope": "sg-smartapp",
"jti": "7538cfcc-98de-4cd2-88f0-fc9325cc68dd"
}
Request
GET /oauth/check_token?token=ACCESS_TOKEN
Headers:
Content-Type: application/x-www-form-urlencoded
Authorization: Basic BASE64_CLIENT_CREDENTIALS
Response
200 Username, Permissions (authorities) etc
{
"user_name": "email@example.com",
"scope": [
"sg-smartapp"
],
"active": true,
"exp": 1503253651,
"authorities": [
"READ_PRIVILEGE",
"WRITE_PRIVILEGE"
],
"jti": "7538cfcc-98de-4cd2-88f0-fc9325cc68dd",
"client_id": "live-test"
}
Request
PUT /api/forgot-password?email=EMAIL_ID_OF_USER
Response
202 Request Accepted. This API returns only 202. If the email is valid and user available with that
email, then reset password token will be sent to that user.
Request
PUT /api/reset-password
Headers:
Content-Type: application/json
{
"token": “UUID_SENT_ON_MAIL",
"password" : "123456",
"confirm_password": "123456"
}
Response
200 If Password updated successfully (No response JSON will be returned)
400 If Validation error occurs
{
"status": "BAD_REQUEST",
"message": "Validation Error",
"timestamp": "2017-08-26T19:21:01.873Z",
"errors": [
{
"field": "token",
"message": "Reset Token is required"
},
{
"field": "password",
"message": "Password is required."
},
{
"message": "Passwords do not match"
}
]
}