Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function cek_sso()
- {
- $return = NULL;
- $href_sso = '?ref=' . encrypt(current_url());
- $href_sso = 'https://kepegawaian-bkpsdm.kuduskab.go.id/sso' . $href_sso;
- $CI = &get_instance();
- $get_cookie = get_cookie('sso');
- // If the SSO cookie exists
- if ($get_cookie !== NULL) {
- $data = dekrip($get_cookie) . '||' . $CI->input->ip_address() . '-' . $CI->agent->agent_string();
- $get = apiku([
- 'url' => 'https://kepegawaian-bkpsdm.kuduskab.go.id/sso/api/token_sso/verify',
- 'header' => ["Content-Type: application/x-www-form-urlencoded", "key: ssobkpsdm"],
- 'post' => 'token=' . encrypt($data),
- ]);
- // If verification fails, redirect to SSO
- if ($get['resp_error'] === TRUE) {
- redirect($href_sso, 'location');
- } else {
- // Set session data on successful verification
- $user_data = $CI->mdl->getdata('v_u_users', "id_user='" . $get['data']['user_id'] . "'")->row();
- $level = $CI->mdl->getdata('tbl_level', "id_level='" . $user_data->id_level . "'")->row();
- $CI->session->set_userdata([
- 'data' => encrypt_data($user_data),
- 'level' => encrypt_data($level),
- 'h' => encrypt(appproperties('appname')),
- ]);
- // Refresh the SSO cookie
- set_cookie([
- 'name' => 'sso',
- 'value' => encrypt(decrypt($get_cookie)),
- 'domain' => 'kepegawaian-bkpsdm.kuduskab.go.id',
- 'expire' => 900, // 15 minutes
- 'secure' => TRUE,
- 'httponly' => TRUE
- ]);
- $return = $get;
- }
- } else {
- redirect($href_sso, 'location');
- }
- return $return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement