ported from mozilla: Bug 1538409 - implement oAuth authentication for POP accounts r=benc a=mkmelin (f6219b04be)

This commit is contained in:
roytam1 2024-09-21 18:23:52 +08:00
commit 08feac8e97
6 changed files with 212 additions and 35 deletions

View file

@ -5618,6 +5618,11 @@ void nsImapProtocol::InitPrefAuthMethods(int32_t authMethodPrefValue)
kHasAuthGssApiCapability |
kHasAuthNTLMCapability | kHasAuthMSNCapability;
break;
#ifdef MOZ_MAILNEWS_OAUTH2
case nsMsgAuthMethod::OAuth2:
m_prefAuthMethods = kHasXOAuth2Capability;
break;
#endif
default:
NS_ASSERTION(false, "IMAP: authMethod pref invalid");
// TODO log to error console
@ -5632,9 +5637,6 @@ void nsImapProtocol::InitPrefAuthMethods(int32_t authMethodPrefValue)
kHasAuthNTLMCapability | kHasAuthMSNCapability |
#ifdef MOZ_MAILNEWS_OAUTH2
kHasAuthExternalCapability | kHasXOAuth2Capability;
break;
case nsMsgAuthMethod::OAuth2:
m_prefAuthMethods = kHasXOAuth2Capability;
#else
kHasAuthExternalCapability;
#endif
@ -5643,13 +5645,16 @@ void nsImapProtocol::InitPrefAuthMethods(int32_t authMethodPrefValue)
}
#ifdef MOZ_MAILNEWS_OAUTH2
if (m_prefAuthMethods & kHasXOAuth2Capability)
if (m_prefAuthMethods & kHasXOAuth2Capability) {
mOAuth2Support = new mozilla::mailnews::OAuth2ThreadHelper(aServer);
// Disable OAuth2 support if we don't have the prefs installed.
if (m_prefAuthMethods & kHasXOAuth2Capability &&
(!mOAuth2Support || !mOAuth2Support->SupportsOAuth2()))
m_prefAuthMethods &= ~kHasXOAuth2Capability;
if (!mOAuth2Support || !mOAuth2Support->SupportsOAuth2()) {
// Disable OAuth2 support if we don't have the prefs installed.
m_prefAuthMethods &= ~kHasXOAuth2Capability;
mOAuth2Support = nullptr;
MOZ_LOG(IMAP, LogLevel::Warning,
("IMAP: no OAuth2 support for this server."));
}
}
#endif
NS_ASSERTION(m_prefAuthMethods != kCapabilityUndefined,
@ -5706,17 +5711,17 @@ nsresult nsImapProtocol::ChooseAuthMethod()
m_currentAuthMethod = kHasAuthOldLoginCapability;
else
{
MOZ_LOG(IMAP, LogLevel::Debug, ("no remaining auth method"));
MOZ_LOG(IMAP, LogLevel::Debug, ("No remaining auth method"));
m_currentAuthMethod = kCapabilityUndefined;
return NS_ERROR_FAILURE;
}
MOZ_LOG(IMAP, LogLevel::Debug, ("trying auth method 0x%llx", m_currentAuthMethod));
MOZ_LOG(IMAP, LogLevel::Debug, ("Trying auth method 0x%llx", m_currentAuthMethod));
return NS_OK;
}
void nsImapProtocol::MarkAuthMethodAsFailed(eIMAPCapabilityFlags failedAuthMethod)
{
MOZ_LOG(IMAP, LogLevel::Debug, ("marking auth method 0x%llx failed", failedAuthMethod));
MOZ_LOG(IMAP, LogLevel::Debug, ("Marking auth method 0x%llx failed", failedAuthMethod));
m_failedAuthMethods |= failedAuthMethod;
}
@ -8594,7 +8599,7 @@ nsImapProtocol::OnPromptCanceled()
bool nsImapProtocol::TryToLogon()
{
MOZ_LOG(IMAP, LogLevel::Debug, ("try to log in"));
MOZ_LOG(IMAP, LogLevel::Debug, ("Try to log in"));
NS_ENSURE_TRUE(m_imapServerSink, false);
bool loginSucceeded = false;
bool skipLoop = false;