<?php

namespace App\libs\google\Gateways;

use Google\Client;
use Illuminate\Support\Facades\Config;

class GoogleOauth
{
    private $config;
    private $client;

    public function __construct()
    {
        $this->config = Config::get('swdz.goodle');
        $this->client = new Client([
            'client_id'     => $this->config['client_id'],
            'client_secret' => $this->config['client_secret'],
            'redirect_uri'  => $this->config['redirect_uri'],
            'scopes'        => $this->config['scopes'],
        ]);
    }

    /**
     * APP通过code换取用户信息.
     *
     * @return array|false
     *
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    public function appAuth()
    {
        $code = request()->get('code', null);

        return $this->client->verifyIdToken($code);
    }

    /**
     * WEB打开授权页面（待补充）.
     */
    public static function webAuth(): void
    {
    }
}
