User Tools


User Check-in operation

Back to JEA API docs


User authentication and authorization is performed by JEA using the JSON Web Tokens (JWT) mechanism. If the client is already holding a JWT, the Check-in operation should be performed before other transactions, in order to check its validity and get an updated token.

Synopsis

Authorization return object

A successful authorization return object contains the status flag, message, user's name, email address, and a new JWT, as shown in the example below.

{
    "ok": true,
    "status": "Logged in successfully!",
    "jwt": "eyJraWQiOiIxNTAyMzE2M......jdrg",
    "user": "Yi",
    "role" : "user",
    "email": "yi@jeplus.org"
}

Example using curl://

Send the check-in command using curl:

curl -H "Authorization:Bearer eyJraWQiOiIxNTAyMzE2Mz...Qons9gjFXUrpQ" -X POST http://jea.ensims.com/users/api/checkin

On successful check-in, an Auth return object with 'OK' status will be received with a new JWT. If the existing JWT is invalid, an HTTP 401 Unauthorized code will be received.

Example using Python Requests

Make sure Requests is correctly installed in your Python environment, and run the following the lines:

import requests

jwt = 'eyJraWQiOiIxNTAyMzE2MzY...JEwH4KoyBqDDTkfjmsQons9gjFXUrpQ'
headers = {'Authorization': 'Bearer ' + jwt}
body = {}

r = requests.post('http://jea.ensims.com/users/api/checkin', headers=headers, json=body)
  
r.json()

A successful operation will return the JSON content such as the following:

{'email': 'yi@jeplus.org',
 'jwt': 'eyJraWQiOiIxNTAyMzE2MzY...O2CN4QDLxM2eUolgak9w',
 'ok': True,
 'role': 'user',
 'status': 'Logged in successfully!',
 'user': 'Yi'}

You can then access each field, e.g. the new JWT, using r.json()['jwt'].


Site Tools