48 lines
1.1 KiB
PHP
48 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Libraries\MySocket;
|
|
|
|
use Google\Client;
|
|
use CodeIgniter\Config\Services;
|
|
use CodeIgniter\Exceptions\ConfigException;
|
|
|
|
class GoogleSocket extends Client
|
|
{
|
|
private $session;
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->session = Services::session();
|
|
$this->setClientId(env('socket.google.client.id'));
|
|
$this->setClientSecret(env('socket.google.client.key'));
|
|
$this->setRedirectUri(base_url(env('socket.google.client.callback_url')));
|
|
$this->addScope('email');
|
|
$this->addScope('profile');
|
|
}
|
|
|
|
public function setToken(string $access_code): void
|
|
{
|
|
// 토큰 정보 가져오기
|
|
$tokenInfo = $this->fetchAccessTokenWithAuthCode($access_code);
|
|
|
|
if (isset($tokenInfo['error'])) {
|
|
throw new ConfigException($tokenInfo['error']);
|
|
}
|
|
|
|
$tokenName = env('socket.google.client.token_name');
|
|
$token = $tokenInfo[$tokenName];
|
|
|
|
// Google Service에 접근하기 위해 Access Token 설정
|
|
$this->setAccessToken($token);
|
|
|
|
// 세션에 Token 값 설정
|
|
$this->session->set($tokenName, $token);
|
|
}
|
|
|
|
public function getToken(): ?string
|
|
{
|
|
return $this->session->get(env('socket.google.client.token_name'));
|
|
}
|
|
}
|