Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 21... Línea 21...
21
 * @copyright  2022 Huong Nguyen <huongnv13@gmail.com>
21
 * @copyright  2022 Huong Nguyen <huongnv13@gmail.com>
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
23
 */
24
class moodle_phpmailer_oauth extends \PHPMailer\PHPMailer\OAuth {
24
class moodle_phpmailer_oauth extends \PHPMailer\PHPMailer\OAuth {
Línea -... Línea 25...
-
 
25
 
25
 
26
    #[\Override]
26
    protected function getToken() {
27
    protected function getToken() {
27
        return $this->provider->get_accesstoken()->token;
28
        return $this->provider->get_accesstoken()->token;
Línea -... Línea 29...
-
 
29
    }
-
 
30
 
-
 
31
    #[\Override]
-
 
32
    public function getOauth64() {
-
 
33
        // Get a new token if it's not available.
-
 
34
        if ($this->oauthToken === null) {
-
 
35
            $this->oauthToken = $this->getToken();
-
 
36
        }
-
 
37
 
-
 
38
        $accesstoken = $this->provider->get_accesstoken();
-
 
39
        // Renew the token if it's expired.
-
 
40
        if (isset($accesstoken->expires) && time() >= $accesstoken->expires) {
-
 
41
            if (isset($accesstoken->refreshtoken)) {
-
 
42
                $this->provider->upgrade_token($accesstoken->refreshtoken, 'refresh_token');
-
 
43
            }
-
 
44
            $this->oauthToken = $this->getToken();
-
 
45
        }
-
 
46
 
-
 
47
        return base64_encode(
-
 
48
            'user=' .
-
 
49
            $this->oauthUserEmail .
-
 
50
            "\001auth=Bearer " .
-
 
51
            $this->oauthToken .
-
 
52
            "\001\001"
28
    }
53
        );