jamboljack

get Token Accurate

Oct 14th, 2023
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.37 KB | None | 0 0
  1. public function gettoken()
  2.     {
  3.         $dataMeta      = $this->db->get_where('app_meta', array('meta_id' => 1))->row();
  4.         $clientId      = $dataMeta->meta_client_id;
  5.         $clientSecret  = $dataMeta->meta_client_secret;
  6.         $oauthCallback = $dataMeta->meta_auth_callback;
  7.  
  8.         // Code setelah Callback, bisakh otomatis
  9.         $code       = trim($this->input->get('code'));
  10.         $baseEncode = $clientId . ':' . $clientSecret;
  11.         $basicAuth  = base64_encode($baseEncode);
  12.         $header     = array(
  13.             "Authorization: Basic " . $basicAuth,
  14.         );
  15.  
  16.         $content = array(
  17.             "code"         => $code,
  18.             "grant_type"   => "authorization_code",
  19.             "redirect_uri" => $oauthCallback,
  20.         );
  21.         $url  = "https://account.accurate.id/oauth/token";
  22.         $opts = array("http" => array(
  23.             "method"        => "POST",
  24.             "header"        => $header,
  25.             "content"       => http_build_query($content),
  26.             "ignore_errors" => true,
  27.         ),
  28.         );
  29.  
  30.         $context       = stream_context_create($opts);
  31.         $response      = file_get_contents($url, false, $context);
  32.         $json          = json_decode($response);
  33.         $access_token  = trim($json->access_token);
  34.         $refresh_token = trim($json->refresh_token);
  35.  
  36.         return $access_token;
  37.     }
Add Comment
Please, Sign In to add comment