function key() { // echo get_api_sig(); $this->load->library('encryption'); $key = $this->encryption->create_key(10); echo base64_encode($key); echo " <br> "; echo urlsafeB64Encode($key); echo " <br> "; echo base64_encode($key); echo " <br> "; }
function authentication_get() { $this->load->library('z_auth/auth'); // CHECK X-API-KEY HEADER $apps_key = $this->input->get_request_header('X-API-KEY'); if (!$this->db->where('api_token', $apps_key)->get('a_system')->row()) { $this->response(['status' => FALSE, 'message' => 'What are you doing...?'], 400); } // BASIC AUTH $username = $this->input->server('PHP_AUTH_USER'); $http_auth = $this->input->server('HTTP_X_AUTH'); $password = NULL; if ($username !== NULL) { $password = $this->input->server('PHP_AUTH_PW'); } elseif ($http_auth !== NULL) { if (strpos(strtolower($http_auth), 'basic') === 0) { list($username, $password) = explode(':', base64_decode(substr($http_auth, 6))); } } if (!($id = $this->auth->login($username, $password))) { $this->response(['status' => FALSE, 'message' => $this->auth->errors()], 401); } // User Data // $user = $this->db->get_where('a_user', ['id'=>$id])->row(); $params['select'] = 'au.id, au.client_id, au.org_id, au.role_id, au.name, au.description, au.email, au.photo_url, ac.name as client_name, ao.name as org_name, ar.name as role_name'; $params['where']['au.id'] = $id; $user = (object) $this->system_model->getUserAuthentication($params)[0]; $dataUser = ['name' => $user->name, 'description' => $user->description, 'email' => $user->email, 'client_name' => $user->client_name, 'org_name' => $user->org_name, 'role_name' => $user->role_name, 'photo_url' => urlencode($user->photo_url)]; $userConfig = (object) $this->system_model->getUserConfig(['select' => 'attribute, value', 'where' => ['user_id' => $id]]); $dataConfig = []; foreach ($userConfig as $k => $v) { $dataConfig[$v->attribute] = $v->value; } $GLOBALS['identifier'] = ['user_id' => $id, 'client_id' => $user->client_id, 'org_id' => $user->org_id, 'role_id' => $user->role_id]; $data = array_merge($GLOBALS['identifier'], $dataUser, $dataConfig); // $this->load->library('encryption'); // $data['authentication'] = $this->encryption->encrypt(json_encode($GLOBALS['identifier'])); $result['data'] = urlsafeB64Encode(json_encode($data)); $this->xresponse(TRUE, $result); }