Client Authentication
Authentication from OpenMRS:
- Create your username and password on your OpenMRS installation. For demo installation see here .
- Send http request to http://yourServer/security/authenticate. For demo http://46.101.51.199:8080/oweb/security/authenticate.
- The response in case of successful authentication will return a Http OK (200) code with details object. Otherwise response would be Http UNAUTHORIZED (401) code with no data.
- The response object would be a json document with two objects mappable to "user" and "locations" of org.opensrp.api.domain.User and org.opensrp.api.util.LocationTree respectively. The user represents complete user details like name, identifiers and other attributes associated, while locations represents the areas or health facilities the worker is responsible for. This is mapped by OpenMRS person attribute Location or Locations with ;; (double semicolon) separated location uuids or names.
- An example response json is below
{ "locations": { "locationsHierarchy": { "map": { "cd4ed528-87cd-42ee-a175-5e7089521ebd": { "id": "cd4ed528-87cd-42ee-a175-5e7089521ebd", "label": "Pakistan", "node": { "locationId": "cd4ed528-87cd-42ee-a175-5e7089521ebd", "name": "Pakistan", "tags": ["Country"], "voided": false }, "children": { "461f2be7-c95d-433c-b1d7-c68f272409d7": { "id": "461f2be7-c95d-433c-b1d7-c68f272409d7", "label": "Sindh", "node": { "locationId": "461f2be7-c95d-433c-b1d7-c68f272409d7", "name": "Sindh", "parentLocation": { "locationId": "cd4ed528-87cd-42ee-a175-5e7089521ebd", "name": "Pakistan", "voided": false }, "tags": ["Province"], "voided": false }, "children": { "a529e2fc-6f0d-4e60-a5df-789fe17cca48": { "id": "a529e2fc-6f0d-4e60-a5df-789fe17cca48", "label": "Karachi", "node": { "locationId": "a529e2fc-6f0d-4e60-a5df-789fe17cca48", "name": "Karachi", "parentLocation": { "locationId": "461f2be7-c95d-433c-b1d7-c68f272409d7", "name": "Sindh", "voided": false }, "tags": ["City"], "voided": false }, "children": { "60c21502-fec1-40f5-b77d-6df3f92771ce": { "id": "60c21502-fec1-40f5-b77d-6df3f92771ce", "label": "Baldia", "node": { "locationId": "60c21502-fec1-40f5-b77d-6df3f92771ce", "name": "Baldia", "parentLocation": { "locationId": "a529e2fc-6f0d-4e60-a5df-789fe17cca48", "name": "Karachi", "voided": false }, "tags": ["Town"], "attributes": {"at1": "atttt1"}, "voided": false }, "parent": "a529e2fc-6f0d-4e60-a5df-789fe17cca48" } }, "parent": "461f2be7-c95d-433c-b1d7-c68f272409d7" } }, "parent": "cd4ed528-87cd-42ee-a175-5e7089521ebd" } } } }, "parentChildren": { "cd4ed528-87cd-42ee-a175-5e7089521ebd": ["461f2be7-c95d-433c-b1d7-c68f272409d7"], "461f2be7-c95d-433c-b1d7-c68f272409d7": ["a529e2fc-6f0d-4e60-a5df-789fe17cca48"], "a529e2fc-6f0d-4e60-a5df-789fe17cca48": ["60c21502-fec1-40f5-b77d-6df3f92771ce"] } } }, "user": { "username": "demotest", "roles": ["Provider", "Thrive Member"], "permissions": ["Add Patients", "Patient Dashboard - View Demographics Section" ], "baseEntityId": "6637559e-ebf9-480a-9731-c47e16e95716", "baseEntity": { "id": "6637559e-ebf9-480a-9731-c47e16e95716", "firstName": "Demo test User", "middleName": "", "lastName": "", "gender": "M", "attributes": { "Location": "cd4ed528-87cd-42ee-a175-5e7089521ebd" }, "voided": false }, "voided": false } }
Note that the user is convertible to org.opensrp.api.domain.User and locations can be converted to org.opensrp.api.util.LocationTree via Gson.
If you donot want to get user or location details and just need to check whether credentials are valid or not, send http request to http://yourServer/authenticate-user . For demo http://46.101.51.199:8080/oweb/authenticate-user .
The response would return with a Http OK code incase of valid credentials and otherwise a Http code UNAUTHORIZED would be returned.
This site is no longer maintained. Please visit docs.opensrp.io for current documentation.