mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-12 18:20:26 +01:00
SMTPClientSession: added support for XOAUTH2 authentication
This commit is contained in:
parent
910e2f3f29
commit
899e5084e9
@ -52,7 +52,8 @@ public:
|
||||
AUTH_CRAM_MD5,
|
||||
AUTH_CRAM_SHA1,
|
||||
AUTH_LOGIN,
|
||||
AUTH_PLAIN
|
||||
AUTH_PLAIN,
|
||||
AUTH_XOAUTH2
|
||||
};
|
||||
|
||||
explicit SMTPClientSession(const StreamSocket& socket);
|
||||
@ -184,6 +185,7 @@ protected:
|
||||
void loginUsingCRAM(const std::string& username, const std::string& method, Poco::DigestEngine& hmac);
|
||||
void loginUsingLogin(const std::string& username, const std::string& password);
|
||||
void loginUsingPlain(const std::string& username, const std::string& password);
|
||||
void loginUsingXOAUTH2(const std::string& username, const std::string& password);
|
||||
DialogSocket& socket();
|
||||
|
||||
private:
|
||||
|
@ -206,6 +206,7 @@ void SMTPClientSession::loginUsingLogin(const std::string& username, const std::
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SMTPClientSession::loginUsingPlain(const std::string& username, const std::string& password)
|
||||
{
|
||||
std::ostringstream credentialsBase64;
|
||||
@ -219,6 +220,19 @@ void SMTPClientSession::loginUsingPlain(const std::string& username, const std::
|
||||
}
|
||||
|
||||
|
||||
void SMTPClientSession::loginUsingXOAUTH2(const std::string& username, const std::string& password)
|
||||
{
|
||||
std::ostringstream credentialsBase64;
|
||||
Base64Encoder credentialsEncoder(credentialsBase64);
|
||||
credentialsEncoder << "user=" << username << "\001auth=Bearer " << password << "\001\001";
|
||||
credentialsEncoder.close();
|
||||
|
||||
std::string response;
|
||||
int status = sendCommand("AUTH XOAUTH2", credentialsBase64.str(), response);
|
||||
if (!isPositiveCompletion(status)) throw SMTPException("Login using XOAUTH2 failed", response, status);
|
||||
}
|
||||
|
||||
|
||||
void SMTPClientSession::login(LoginMethod loginMethod, const std::string& username, const std::string& password)
|
||||
{
|
||||
login(Environment::nodeName(), loginMethod, username, password);
|
||||
@ -262,6 +276,14 @@ void SMTPClientSession::login(const std::string& hostname, LoginMethod loginMeth
|
||||
}
|
||||
else throw SMTPException("The mail service does not support PLAIN authentication", response);
|
||||
}
|
||||
else if (loginMethod == AUTH_XOAUTH2)
|
||||
{
|
||||
if (response.find("XOAUTH2", 0) != std::string::npos)
|
||||
{
|
||||
loginUsingXOAUTH2(username, password);
|
||||
}
|
||||
else throw SMTPException("The mail service does not support XOAUTH2 authentication", response);
|
||||
}
|
||||
else if (loginMethod != AUTH_NONE)
|
||||
{
|
||||
throw SMTPException("The autentication method is not supported");
|
||||
|
Loading…
Reference in New Issue
Block a user