43 lines
946 B
PHP
43 lines
946 B
PHP
<?php
|
|
|
|
namespace App\Libraries\MySocket;
|
|
|
|
use CodeIgniter\Config\Services;
|
|
use CodeIgniter\Exceptions\ConfigException;
|
|
use Google\Client;
|
|
|
|
class GoogleSocket extends Client
|
|
{
|
|
private $session;
|
|
private string $token_name;
|
|
public function __construct(string $token_name)
|
|
{
|
|
parent::__construct();
|
|
$this->session = Services::session();
|
|
$this->token_name = $token_name;
|
|
}
|
|
|
|
public function setToken(string $access_code): void
|
|
{
|
|
// 토큰 정보 가져오기
|
|
$tokenInfo = $this->fetchAccessTokenWithAuthCode($access_code);
|
|
|
|
if (isset($tokenInfo['error'])) {
|
|
throw new ConfigException($tokenInfo['error']);
|
|
}
|
|
|
|
$token = $tokenInfo[$this->token_name];
|
|
|
|
// Google Service에 접근하기 위해 Access Token 설정
|
|
$this->setAccessToken($token);
|
|
|
|
// 세션에 Token 값 설정
|
|
$this->session->set($this->token_name, $token);
|
|
}
|
|
|
|
public function getToken(): ?string
|
|
{
|
|
return $this->session->get($this->token_name);
|
|
}
|
|
}
|