ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
OAuth.php
Go to the documentation of this file.
1<?php
21namespace PHPMailer\PHPMailer;
22
23use League\OAuth2\Client\Grant\RefreshToken;
24use League\OAuth2\Client\Provider\AbstractProvider;
25use League\OAuth2\Client\Token\AccessToken;
26
35class OAuth
36{
42 protected $provider;
43
49 protected $oauthToken;
50
57 protected $oauthUserEmail = '';
58
64 protected $oauthClientSecret = '';
65
71 protected $oauthClientId = '';
72
78 protected $oauthRefreshToken = '';
79
86 public function __construct($options)
87 {
88 $this->provider = $options['provider'];
89 $this->oauthUserEmail = $options['userName'];
90 $this->oauthClientSecret = $options['clientSecret'];
91 $this->oauthClientId = $options['clientId'];
92 $this->oauthRefreshToken = $options['refreshToken'];
93 }
94
100 protected function getGrant()
101 {
102 return new RefreshToken();
103 }
104
110 protected function getToken()
111 {
112 return $this->provider->getAccessToken(
113 $this->getGrant(),
114 ['refresh_token' => $this->oauthRefreshToken]
115 );
116 }
117
123 public function getOauth64()
124 {
125 // Get a new token if it's not available or has expired
126 if (null === $this->oauthToken || $this->oauthToken->hasExpired()) {
127 $this->oauthToken = $this->getToken();
128 }
129
130 return base64_encode(
131 'user=' .
132 $this->oauthUserEmail .
133 "\001auth=Bearer " .
134 $this->oauthToken .
135 "\001\001"
136 );
137 }
138}
An exception for terminatinating execution or to throw for unit testing.
OAuth - OAuth2 authentication wrapper class.
Definition: OAuth.php:36
getGrant()
Get a new RefreshToken.
Definition: OAuth.php:100
getOauth64()
Generate a base64-encoded OAuth token.
Definition: OAuth.php:123
__construct($options)
OAuth constructor.
Definition: OAuth.php:86
getToken()
Get a new AccessToken.
Definition: OAuth.php:110
Get an OAuth2 token from an OAuth2 provider.