Merge pull request #3170 from llemoine/master
XOAUTH : Added support for long auth tokens
This commit is contained in:
commit
a2fa102104
39
src/SMTP.php
39
src/SMTP.php
|
|
@ -633,10 +633,41 @@ class SMTP
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$oauth = $OAuth->getOauth64();
|
$oauth = $OAuth->getOauth64();
|
||||||
|
/*
|
||||||
//Start authentication
|
* An SMTP command line can have a maximum length of 512 bytes, including the command name,
|
||||||
if (!$this->sendCommand('AUTH', 'AUTH XOAUTH2 ' . $oauth, 235)) {
|
* so the base64-encoded OAUTH token has a maximum length of:
|
||||||
return false;
|
* 512 - 13 (AUTH XOAUTH2) - 2 (CRLF) = 497 bytes
|
||||||
|
* If the token is longer than that, the command and the token must be sent separately as described in
|
||||||
|
* https://www.rfc-editor.org/rfc/rfc4954#section-4
|
||||||
|
*/
|
||||||
|
if ($oauth === '') {
|
||||||
|
//Sending an empty auth token is legitimate, but it must be encoded as '='
|
||||||
|
//to indicate it's not a 2-part command
|
||||||
|
if (!$this->sendCommand('AUTH', 'AUTH XOAUTH2 =', 235)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} elseif (strlen($oauth) <= 497) {
|
||||||
|
//Authenticate using a token in the initial-response part
|
||||||
|
if (!$this->sendCommand('AUTH', 'AUTH XOAUTH2 ' . $oauth, 235)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//The token is too long, so we need to send it in two parts.
|
||||||
|
//Send the auth command without a token and expect a 334
|
||||||
|
if (!$this->sendCommand('AUTH', 'AUTH XOAUTH2', 334)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//Send the token
|
||||||
|
if (!$this->sendCommand('OAuth TOKEN', $oauth, [235, 334])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//If the server answers with 334, send an empty line and wait for a 235
|
||||||
|
if (
|
||||||
|
substr($this->last_reply, 0, 3) === '334'
|
||||||
|
&& $this->sendCommand('AUTH End', '', 235)
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue