separate auth
This commit is contained in:
parent
220ad53286
commit
b046d2a289
@ -57,7 +57,7 @@ class Filters extends BaseFilters
|
|||||||
'after' => [
|
'after' => [
|
||||||
'pagecache', // Web Page Caching
|
'pagecache', // Web Page Caching
|
||||||
'performance', // Performance Metrics
|
'performance', // Performance Metrics
|
||||||
//'toolbar', // Debug Toolbar
|
'toolbar', // Debug Toolbar
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,8 @@ use CodeIgniter\Router\RouteCollection;
|
|||||||
* @var RouteCollection $routes
|
* @var RouteCollection $routes
|
||||||
*/
|
*/
|
||||||
$routes->get('/', 'Pages::home');
|
$routes->get('/', 'Pages::home');
|
||||||
$routes->get('/login', 'Auths::login');
|
$routes->get('/loginsby', 'Auths::loginSBY');
|
||||||
|
$routes->get('/logindps', 'Auths::loginDPS');
|
||||||
//$routes->get('/tests', 'Auths::tests');
|
//$routes->get('/tests', 'Auths::tests');
|
||||||
$routes->post('/api/requests/', 'API_Requests::requests');
|
$routes->post('/api/requests/', 'API_Requests::requests');
|
||||||
$routes->get('/api/requests/orm/(:any)', 'API_Requests::orm/$1');
|
$routes->get('/api/requests/orm/(:any)', 'API_Requests::orm/$1');
|
||||||
|
|||||||
@ -172,7 +172,8 @@ WHERE tu.SP_ACCESSNUMBER = '$accessnumber';";
|
|||||||
|
|
||||||
public function results_send($accessnumber) {
|
public function results_send($accessnumber) {
|
||||||
//$TM_url = "https://api-transmedic1.transmedic.co.id/api/webhook/lis";
|
//$TM_url = "https://api-transmedic1.transmedic.co.id/api/webhook/lis";
|
||||||
$TM_url = "http://10.10.4.123:8001/api/webhook/lis";
|
$TMSby_url = "http://10.10.4.123:8001/api/webhook/lis";
|
||||||
|
$TMBali_url = "http://10.10.12.90:8001/api/webhook/lis";
|
||||||
$TMBali_bearerToken = file_get_contents('tokens/pbmc_dps.txt');
|
$TMBali_bearerToken = file_get_contents('tokens/pbmc_dps.txt');
|
||||||
$TMSby_bearerToken = file_get_contents('tokens/pbmc_sby.txt');
|
$TMSby_bearerToken = file_get_contents('tokens/pbmc_sby.txt');
|
||||||
|
|
||||||
@ -180,8 +181,13 @@ WHERE tu.SP_ACCESSNUMBER = '$accessnumber';";
|
|||||||
|
|
||||||
$json = $this->create_json($accessnumber);
|
$json = $this->create_json($accessnumber);
|
||||||
$location = $json['branch'];
|
$location = $json['branch'];
|
||||||
if($location == 'PBMC Surabaya') { $token = $TMSby_bearerToken; }
|
if($location == 'PBMC Surabaya') {
|
||||||
else { $token = $TMBali_bearerToken; }
|
$token = $TMSby_bearerToken;
|
||||||
|
$TM_url = $TMSby_url;
|
||||||
|
} else {
|
||||||
|
$token = $TMBali_bearerToken;
|
||||||
|
$TM_url = $TMBali_url;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$response = $client->request('POST', $TM_url, [
|
$response = $client->request('POST', $TM_url, [
|
||||||
|
|||||||
@ -3,90 +3,81 @@ namespace App\Controllers;
|
|||||||
|
|
||||||
class Auths extends BaseController {
|
class Auths extends BaseController {
|
||||||
|
|
||||||
public function login() {
|
public function loginDPS() {
|
||||||
//$TM_url = "https://api-transmedic1.transmedic.co.id/api/token/create";
|
$file = "tokens/pbmc_dps.txt";
|
||||||
$TM_url = "http://10.10.4.123:8001/api/token/create";
|
//$TM_url = "https://staging-eklinik.pbmcgroup.com/api/token/create";
|
||||||
//$TM_url = "http://cmod-rest.local/tests";
|
$TM_url = "http://10.10.12.90:8001/api/token/create";
|
||||||
$fileSBY = "tokens/pbmc_sby.txt";
|
|
||||||
$fileDPS = "tokens/pbmc_dps.txt";
|
|
||||||
|
|
||||||
$secret = "o7lf5DUxSuPKtDjlbqc2VuZD9WjQ5qAZ";
|
$secret = "o7lf5DUxSuPKtDjlbqc2VuZD9WjQ5qAZ";
|
||||||
|
$header = [ 'typ' => 'JWT', 'alg' => 'HS256' ];
|
||||||
//$credSBY = [ "username"=>"pbmc_surabaya", "password"=>"pgcWfdwX3qEt9zaC" ];
|
$payload = [
|
||||||
//$credDPS = [ "username"=>"pbmc_bali", "password"=>"J8e29XjLmDCFuQnk" ];
|
|
||||||
|
|
||||||
$header = [
|
|
||||||
'typ' => 'JWT',
|
|
||||||
'alg' => 'HS256'
|
|
||||||
];
|
|
||||||
|
|
||||||
$payloadSBY = [
|
|
||||||
'iat' => time(),
|
|
||||||
'data'=> [
|
|
||||||
'username'=>"pbmc_surabaya",
|
|
||||||
'password'=>"pgcWfdwX3qEt9zaC"
|
|
||||||
]
|
|
||||||
];
|
|
||||||
|
|
||||||
$payloadDPS = [
|
|
||||||
'iat' => time(),
|
'iat' => time(),
|
||||||
'data'=> [
|
'data'=> [
|
||||||
'username'=>"pbmc_bali",
|
'username'=>"pbmc_bali",
|
||||||
'password'=>"J8e29XjLmDCFuQnk"
|
'password'=>"J8e29XjLmDCFuQnk"
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
$jwt = $this->createJWT($header, $payload, $secret);
|
||||||
|
$this->token2file($TM_url, $jwt, $file);
|
||||||
|
}
|
||||||
|
|
||||||
function base64UrlEncode($data) {
|
public function loginSBY() {
|
||||||
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
|
$TM_url = "http://10.10.4.123:8001/api/token/create";
|
||||||
}
|
$file = "tokens/pbmc_sby.txt";
|
||||||
|
$secret = "o7lf5DUxSuPKtDjlbqc2VuZD9WjQ5qAZ";
|
||||||
|
$header = [ 'typ' => 'JWT', 'alg' => 'HS256' ];
|
||||||
|
$payload = [
|
||||||
|
'iat' => time(),
|
||||||
|
'data'=> [
|
||||||
|
'username'=>"pbmc_surabaya",
|
||||||
|
'password'=>"pgcWfdwX3qEt9zaC"
|
||||||
|
]
|
||||||
|
];
|
||||||
|
$jwt = $this->createJWT($header, $payload, $secret);
|
||||||
|
$this->token2file($TM_url, $jwt, $file);
|
||||||
|
}
|
||||||
|
|
||||||
function createJWT($header, $payload, $secret) {
|
private function base64UrlEncode($data) {
|
||||||
$encodedHeader = base64UrlEncode(json_encode($header));
|
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
|
||||||
$encodedPayload = base64UrlEncode(json_encode($payload));
|
}
|
||||||
|
|
||||||
$signature = hash_hmac('sha256', "$encodedHeader.$encodedPayload", $secret, true);
|
private function createJWT($header, $payload, $secret) {
|
||||||
$encodedSignature = base64UrlEncode($signature);
|
$encodedHeader = $this->base64UrlEncode(json_encode($header));
|
||||||
|
$encodedPayload = $this->base64UrlEncode(json_encode($payload));
|
||||||
|
|
||||||
// Combine to create the JWT
|
$signature = hash_hmac('sha256', "$encodedHeader.$encodedPayload", $secret, true);
|
||||||
$jwt = "$encodedHeader.$encodedPayload.$encodedSignature";
|
$encodedSignature = $this->base64UrlEncode($signature);
|
||||||
return $jwt;
|
|
||||||
}
|
|
||||||
|
|
||||||
function token2file($TM_url, $jwt, $file ) {
|
// Combine to create the JWT
|
||||||
$client = \Config\Services::curlrequest();
|
$jwt = "$encodedHeader.$encodedPayload.$encodedSignature";
|
||||||
try {
|
return $jwt;
|
||||||
$response = $client->request('GET', $TM_url, [
|
}
|
||||||
"headers" => [
|
|
||||||
"AppCode" => "2",
|
|
||||||
"Accept" => "application/json",
|
|
||||||
"Authorization" => "Bearer $jwt"
|
|
||||||
],
|
|
||||||
"body" => '',
|
|
||||||
"verify" => false
|
|
||||||
]);
|
|
||||||
|
|
||||||
if ($response->getStatusCode() == 200) {
|
private function token2file($TM_url, $jwt, $file ) {
|
||||||
$body = $response->getBody();
|
$client = \Config\Services::curlrequest();
|
||||||
$data = json_decode($body, true);
|
try {
|
||||||
$token = $data['data']['token'];
|
$response = $client->request('GET', $TM_url, [
|
||||||
if (file_put_contents($file, $token) !== false) {
|
"headers" => [
|
||||||
echo "Response saved to: " . $file . "<br/>";
|
"AppCode" => "2",
|
||||||
}
|
"Accept" => "application/json",
|
||||||
} else {
|
"Authorization" => "Bearer $jwt"
|
||||||
print_r($response);
|
],
|
||||||
|
"body" => '',
|
||||||
|
"verify" => false
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($response->getStatusCode() == 200) {
|
||||||
|
$body = $response->getBody();
|
||||||
|
$data = json_decode($body, true);
|
||||||
|
$token = $data['data']['token'];
|
||||||
|
if (file_put_contents($file, $token) !== false) {
|
||||||
|
echo "Response saved to: " . $file . "<br/>";
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} else {
|
||||||
echo "Error: " . $e->getMessage();
|
print_r($response);
|
||||||
}
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
echo "Error: " . $e->getMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$jwtSBY = createJWT($header, $payloadSBY, $secret);
|
|
||||||
$jwtDPS = createJWT($header, $payloadDPS, $secret);
|
|
||||||
|
|
||||||
token2file($TM_url, $jwtSBY, $fileSBY);
|
|
||||||
token2file($TM_url, $jwtDPS, $fileDPS);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1 +1 @@
|
|||||||
3638|eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOm51bGwsImF1ZCI6IjEwLjEwLjEyLjkwOjgwMDEiLCJpYXQiOjE3Mzg3Nzc0OTEsImV4cCI6MTczODg2Mzg5MSwic3ViIjpudWxsLCJqdGkiOiJlZGUzNzI1NS0yNzE0LTRkNWQtYjlkMS1kZDJlN2NjMjQwZDUiLCJkYXRhIjp7InVzZXJuYW1lIjoicGJtY19iYWxpIiwicGFzc3dvcmQiOiJKOGUyOVhqTG1EQ0Z1UW5rIn19.yLiEfVfdvERzFGBNO2ySpI2kpQowtvdbcbQyR_Q9aa4
|
3919|eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOm51bGwsImF1ZCI6IjEwLjEwLjEyLjkwOjgwMDEiLCJpYXQiOjE3Mzk1OTIzNTksImV4cCI6MTczOTY3ODc1OSwic3ViIjpudWxsLCJqdGkiOiI1Yzk0Zjk0MC1jY2M4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