Open SSO API Documentation
Open SSO basically is a Rest API first system. Here is the fundamental API list to use in your website.
Table Of Contents
- A. Verify Token
- B. Get My Profile
- C. Update My Profile
- D. Deactivate My Profile
- E. Get Another User Profile
- F. API via Postman
Learn more
X-Token
X-Token is a header that should be filled with JWT token generated from user login.
Most API request in Open SSO will require X-Token
header.
You can get X-Token in three different ways.
1. Login Normal
Get X-Token via login normal.
Method | Endpoint | Header | Body |
---|---|---|---|
POST | http://localhost:3000/api/user/login | Content-Type: application/json | {“username”: “”, “password”: “”} |
Example output response
|
2. Login via Oauth
User who registered using oauth Google or Apple will require this API.
Note:
- This method will auto register new user if an username or email not exists inside OpenSSO.
- You should follow the oauth flow Google and Apple or bad person could spamming your application.
- If you not sure or can’t follow the oauth Google and Apple, you better use
Login via SSO Login Page
.
a. Get Access Token
You need to have SSO Key
, by create your SSO inside menu My SSO
.
See picture below
Method | Endpoint | Header | Body |
---|---|---|---|
GET | http://localhost:3000/api/oauth/request_token | Content-Type: application/json, Access-Key: {{YOUR_SSO_KEY}} |
Example output response
|
Note:
SSO Key
have no expiring time, but you can’t use it again if its status disabled or removed fromMy SSO
menu.
b. Get X-Token
Once you have the access-token
, you can use it to request X-Token
.
Method | Endpoint | Header | Body |
---|---|---|---|
POST | http://localhost:3000/api/oauth/google | Content-Type: application/json, Access-Token: {{YOUR_ACCESS_TOKEN}} | {“username”:“yourusername”, “email”:“youremail@gmail.com”,“gravatar”:""} |
Apple
Method | Endpoint | Header | Body |
---|---|---|---|
POST | http://localhost:3000/api/oauth/apple | Content-Type: application/json, Access-Token: {{YOUR_ACCESS_TOKEN}} | {“username”:“yourusername”, “email”:“youremail@gmail.com”} |
Example output response
|
3. Login via SSO Login Page
The simpler and safer is just use SSO Login Page to get the X-Token
. But there is some tricky because Google Login Button can’t displayed in Android WebView as default.
API
If you already have the X-Token
, then you can access all APIs below here.
A. Verify Token
When you have the new token, you shouldn’t need to verify it all the time. This API is created just for test only.
Method | Endpoint | Header | Body |
---|---|---|---|
POST | http://localhost:3000/api/auth/verify | X-Token: {{YOUR_TOKEN}} |
Example output response
|
Explanation
uid
is your user id.unm
is your username.name
is your fullname.mail
is your email address.role
is the level of user.gravatar
is the global avatar of user.hash
is the random generated string, only used for internal system.
Below here is the JWT standard which is described in RFC7519:
iat
is identifies the time at which the JWT was issued.exp
is expiration time for JWT.
Note:
- As alternative, you are able to verify your token through JWT.io.
- To make the signature valid on JWT.io, you have to paste your
private.key
andpublic.key
to its website.
B. Get My Profile
This API is to show your user information
Method | Endpoint | Header | Body |
---|---|---|---|
POST | http://localhost:3000/api/user/my-profile | X-Token: {{YOUR_TOKEN}} |
Example output response
|
C. Update My Profile
This API is to modify your user information
Method | Endpoint | Header | Body |
---|---|---|---|
POST | http://localhost:3000/api/user/my-profile/update | X-Token: {{YOUR_TOKEN}}, Content-Type: application/json | {“fullname”: “M ABD AZIZ ALFIAN”, “email”: “aalfiann@gmail.com”, “data”: {“address”: “Jakarta Timur DKI Jakarta”, “about_me”: “Just ordinary developer”}} |
Example output response
|
Note:
- Field
data
is an object type, you can set whatever information on your data user.
D. Deactivate My Profile
This API is to deactivate or delete your account.
Method | Endpoint | Header | Body |
---|---|---|---|
POST | http://localhost:3000/api/user/my-profile/suspend | X-Token: {{YOUR_TOKEN}}, Content-Type: application/json | {“username”: “aalfiann”} |
Example output response
|
Note:
- This action will make your profile deactivated and permanently suspended.
- Nobody can’t find you anymore.
- Your username will not available anymore (nobody can’t use your username).
E. Get Another User Profile
This API is to show another user information.
Method | Endpoint | Header | Body |
---|---|---|---|
GET | http://localhost:3000/api/user/profile/«username» |
Example output response
|
Note:
- Replace
<<username>>
with the username of other user. - This is public API, so you can request it without X-Token header.
F. API via Postman
There is 50 API used in Open SSO. Many of them are used for internal system. You can learn it or make an experiment directly using Postman
. Just import the file postman_collection.json
(located at root directory) to your Postman Application.
Response Format
Here is the default response format, any request will having message
and statusCode
key properties. The error
key property will shown only at 4xx
and 5xx
http status code.
- Success
|
- Created
|
- Bad Request
|
- Unauthorized
|
- Forbidden
|
- Not Found
|
- Internal Server Error
|