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