Advertisement
jamboljack

cek SSO

Jul 19th, 2024
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.04 KB | None | 0 0
  1. public function cek_sso()
  2.     {
  3.         $return     = NULL;
  4.         $href_sso   = '?ref=' . encrypt(current_url());
  5.         $href_sso   = 'https://kepegawaian-bkpsdm.kuduskab.go.id/sso' . $href_sso;
  6.         $CI         = &get_instance();
  7.         $get_cookie = get_cookie('sso');
  8.  
  9.         // If the SSO cookie exists
  10.         if ($get_cookie !== NULL) {
  11.             $data   = dekrip($get_cookie) . '||' . $CI->input->ip_address() . '-' . $CI->agent->agent_string();
  12.             $get    = apiku([
  13.                 'url'       => 'https://kepegawaian-bkpsdm.kuduskab.go.id/sso/api/token_sso/verify',
  14.                 'header'    => ["Content-Type: application/x-www-form-urlencoded", "key: ssobkpsdm"],
  15.                 'post'      => 'token=' . encrypt($data),
  16.             ]);
  17.  
  18.             // If verification fails, redirect to SSO
  19.             if ($get['resp_error'] === TRUE) {
  20.                 redirect($href_sso, 'location');
  21.             } else {
  22.                 // Set session data on successful verification
  23.                 $user_data  = $CI->mdl->getdata('v_u_users', "id_user='" . $get['data']['user_id'] . "'")->row();
  24.                 $level      = $CI->mdl->getdata('tbl_level', "id_level='" . $user_data->id_level . "'")->row();
  25.                
  26.                 $CI->session->set_userdata([
  27.                     'data'  => encrypt_data($user_data),
  28.                     'level' => encrypt_data($level),
  29.                     'h'     => encrypt(appproperties('appname')),
  30.                 ]);
  31.  
  32.                 // Refresh the SSO cookie
  33.                 set_cookie([
  34.                     'name'      => 'sso',
  35.                     'value'     => encrypt(decrypt($get_cookie)),
  36.                     'domain'    => 'kepegawaian-bkpsdm.kuduskab.go.id',
  37.                     'expire'    => 900, // 15 minutes
  38.                     'secure'    => TRUE,
  39.                     'httponly'  => TRUE
  40.                 ]);
  41.  
  42.                 $return = $get;
  43.             }
  44.         } else {
  45.             redirect($href_sso, 'location');
  46.         }
  47.  
  48.         return $return;
  49.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement