Tất cả các request đến Phoebus REST API server đều cần Authentication Token.
Để sử dụng Phoebus API, trước tiên, người dùng cần đăng nhập vào hệ thống. Sau khi đăng nhập thành công, hệ thống sẽ trả về thông tin người dùng cùng Authentication Token.
Token được sử dụng cho các request tiếp theo đến Server. Server sẽ yêu cầu người dùng gửi kèm Token nếu Token không được gửi kèm trong request.
Khi tích hợp với các phần mềm khác, ta cần tạo 1 tài khoản Operator Definition và ban quyền truy cập cho tài khoản này.
Để đăng nhập với tài khoản tích hợp, người dùng sử dụng API sau:
GET ServiceEndPoint/login
Request Header:
OD user
OD password
Kết quả nếu đăng nhập thành công:
Các user của ứng dụng di động được tạo bằng chức năng Mobile User các tài khoản này sẽ được map vào 1 tài khoản Operator Definition dùng chung.
Khi ứng dụng di động đăng nhập, ta dùng API:
GET ServiceEndPoint/pbs_bo_authentication_mobilelogin
Request Header:
mobile user name
Bất kỳ request nào không phải login request đều yêu cầu token ở request header
Ví dụ liệt kê danh mục tên và địa chỉ
var client = new RestClient("http://localhost:54009/PhoebusAPI/pbs_BO_LA_NA");
client.Timeout = -1;
var request = new RestRequest(Method.GET);
request.AddHeader("Authorization", "Bearer AAEAAAD/////AQAAAAAAAAAMA ....");
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
var settings = {
"url": "http://localhost:54009/PhoebusAPI/pbs_BO_LA_NA",
"method": "GET",
"timeout": 0,
"headers": {
"Authorization": "Bearer AAEAAAD/////AQAAAAAAAAAMA ......."
},
};
$.ajax(settings).done(function (response) {
console.log(response);
});
<?php
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('http://localhost:54009/PhoebusAPI/pbs_BO_LA_NA');
$request->setMethod(HTTP_Request2::METHOD_GET);
$request->setConfig(array(
'follow_redirects' => TRUE
));
$request->setHeader(array(
'Authorization' => 'Bearer AAEAAAD/////AQAAAAAAAAAMA .....'
));
try {
$response = $request->send();
if ($response->getStatus() == 200) {
echo $response->getBody();
}
else {
echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
$response->getReasonPhrase();
}
}
catch(HTTP_Request2_Exception $e) {
echo 'Error: ' . $e->getMessage();
}
Updated on : 2021-08-13 06:05:36. by : . at T470-01.
Topic : authentication