mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-25 18:07:31 +09:00
Issue #1258 - Part 8: Ifdef MailNews OAuth2 Support
Use --disable-mailnews-oauth2 to exclude it. Confvars won't be respected.
This commit is contained in:
parent
971009881c
commit
1531d6498d
27 changed files with 193 additions and 23 deletions
|
|
@ -50,8 +50,10 @@ AccountConfig.prototype =
|
|||
*/
|
||||
incomingAlternatives : null,
|
||||
outgoingAlternatives : null,
|
||||
#ifdef MOZ_MAILNEWS_OAUTH2
|
||||
// OAuth2 configuration, if needed.
|
||||
oauthSettings : null,
|
||||
#endif
|
||||
// just an internal string to refer to this. Do not show to user.
|
||||
id : null,
|
||||
// who created the config.
|
||||
|
|
|
|||
|
|
@ -28,10 +28,12 @@ function createAccountInBackend(config)
|
|||
if (config.rememberPassword && config.incoming.password.length)
|
||||
rememberPassword(inServer, config.incoming.password);
|
||||
|
||||
#ifdef MOZ_MAILNEWS_OAUTH2
|
||||
if (inServer.authMethod == Ci.nsMsgAuthMethod.OAuth2) {
|
||||
inServer.setCharValue("oauth2.scope", config.oauthSettings.scope);
|
||||
inServer.setCharValue("oauth2.issuer", config.oauthSettings.issuer);
|
||||
}
|
||||
#endif
|
||||
|
||||
// SSL
|
||||
if (config.incoming.socketType == 1) // plain
|
||||
|
|
@ -107,6 +109,7 @@ function createAccountInBackend(config)
|
|||
rememberPassword(outServer, config.incoming.password);
|
||||
}
|
||||
|
||||
#ifdef MOZ_MAILNEWS_OAUTH2
|
||||
if (outServer.authMethod == Ci.nsMsgAuthMethod.OAuth2) {
|
||||
let pref = "mail.smtpserver." + outServer.key + ".";
|
||||
Services.prefs.setCharPref(pref + "oauth2.scope",
|
||||
|
|
@ -114,6 +117,7 @@ function createAccountInBackend(config)
|
|||
Services.prefs.setCharPref(pref + "oauth2.issuer",
|
||||
config.oauthSettings.issuer);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (config.outgoing.socketType == 1) // no SSL
|
||||
outServer.socketType = Ci.nsMsgSocketType.plain;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,9 @@
|
|||
Components.utils.import("resource:///modules/mailServices.js");
|
||||
Components.utils.import("resource://gre/modules/Services.jsm");
|
||||
Components.utils.import("resource:///modules/hostnameUtils.jsm");
|
||||
#ifdef MOZ_MAILNEWS_OAUTH2
|
||||
Components.utils.import("resource://gre/modules/OAuth2Providers.jsm");
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This is the dialog opened by menu File | New account | Mail... .
|
||||
|
|
@ -184,7 +186,9 @@ EmailConfigWizard.prototype =
|
|||
"authPasswordEncrypted");
|
||||
setLabelFromStringBundle("in-authMethod-kerberos", "authKerberos");
|
||||
setLabelFromStringBundle("in-authMethod-ntlm", "authNTLM");
|
||||
#ifdef MOZ_MAILNEWS_OAUTH2
|
||||
setLabelFromStringBundle("in-authMethod-oauth2", "authOAuth2");
|
||||
#endif
|
||||
setLabelFromStringBundle("out-authMethod-no", "authNo");
|
||||
setLabelFromStringBundle("out-authMethod-password-cleartext",
|
||||
"authPasswordCleartextViaSSL"); // will warn about insecure later
|
||||
|
|
@ -1014,7 +1018,11 @@ EmailConfigWizard.prototype =
|
|||
e("incoming_ssl").value = sanitize.enum(config.incoming.socketType,
|
||||
[ 0, 1, 2, 3 ], 0);
|
||||
e("incoming_authMethod").value = sanitize.enum(config.incoming.auth,
|
||||
#ifdef MOZ_MAILNEWS_OAUTH2
|
||||
[ 0, 3, 4, 5, 6, 10 ], 0);
|
||||
#else
|
||||
[ 0, 3, 4, 5, 6 ], 0);
|
||||
#endif
|
||||
e("incoming_username").value = config.incoming.username;
|
||||
if (config.incoming.port) {
|
||||
e("incoming_port").value = config.incoming.port;
|
||||
|
|
@ -1023,6 +1031,7 @@ EmailConfigWizard.prototype =
|
|||
}
|
||||
this.fillPortDropdown(config.incoming.type);
|
||||
|
||||
#ifdef MOZ_MAILNEWS_OAUTH2
|
||||
// If the hostname supports OAuth2 and imap is enabled, enable OAuth2.
|
||||
let iDetails = OAuth2Providers.getHostnameDetails(config.incoming.hostname);
|
||||
gEmailWizardLogger.info("OAuth2 details for incoming hostname " +
|
||||
|
|
@ -1035,6 +1044,7 @@ EmailConfigWizard.prototype =
|
|||
// store them in the base configuration.
|
||||
this._currentConfig.oauthSettings = config.oauthSettings;
|
||||
}
|
||||
#endif
|
||||
|
||||
// outgoing server
|
||||
e("outgoing_hostname").value = config.outgoing.hostname;
|
||||
|
|
@ -1052,6 +1062,7 @@ EmailConfigWizard.prototype =
|
|||
this.adjustOutgoingPortToSSLAndProtocol(config);
|
||||
}
|
||||
|
||||
#ifdef MOZ_MAILNEWS_OAUTH2
|
||||
// If the hostname supports OAuth2 and imap is enabled, enable OAuth2.
|
||||
let oDetails = OAuth2Providers.getHostnameDetails(config.outgoing.hostname);
|
||||
gEmailWizardLogger.info("OAuth2 details for outgoing hostname " +
|
||||
|
|
@ -1064,6 +1075,7 @@ EmailConfigWizard.prototype =
|
|||
// store them in the base configuration.
|
||||
this._currentConfig.oauthSettings = config.oauthSettings;
|
||||
}
|
||||
#endif
|
||||
|
||||
// populate fields even if existingServerKey, in case user changes back
|
||||
if (config.outgoing.existingServerKey) {
|
||||
|
|
@ -1614,10 +1626,12 @@ EmailConfigWizard.prototype =
|
|||
self._currentConfig.incoming.username = successfulConfig.incoming.username;
|
||||
self._currentConfig.outgoing.username = successfulConfig.outgoing.username;
|
||||
|
||||
#ifdef MOZ_MAILNEWS_OAUTH2
|
||||
// We loaded dynamic client registration, fill this data back in to the
|
||||
// config set.
|
||||
if (successfulConfig.oauthSettings)
|
||||
self._currentConfig.oauthSettings = successfulConfig.oauthSettings;
|
||||
#endif
|
||||
|
||||
self.finish();
|
||||
},
|
||||
|
|
|
|||
|
|
@ -309,7 +309,9 @@
|
|||
<menuitem id="in-authMethod-password-encrypted" value="4"/>
|
||||
<menuitem id="in-authMethod-kerberos" value="5"/>
|
||||
<menuitem id="in-authMethod-ntlm" value="6"/>
|
||||
#ifdef MOZ_MAILNEWS_OAUTH2
|
||||
<menuitem id="in-authMethod-oauth2" value="10" hidden="true"/>
|
||||
#endif
|
||||
</menupopup>
|
||||
</menulist>
|
||||
</row>
|
||||
|
|
@ -359,7 +361,9 @@
|
|||
<menuitem id="out-authMethod-password-encrypted" value="4"/>
|
||||
<menuitem id="out-authMethod-kerberos" value="5"/>
|
||||
<menuitem id="out-authMethod-ntlm" value="6"/>
|
||||
#ifdef MOZ_MAILNEWS_OAUTH2
|
||||
<menuitem id="out-authMethod-oauth2" value="10" hidden="true"/>
|
||||
#endif
|
||||
</menupopup>
|
||||
</menulist>
|
||||
</row>
|
||||
|
|
|
|||
|
|
@ -60,11 +60,13 @@ function guessConfig(domain, progressCallback, successCallback, errorCallback,
|
|||
assert(typeof(successCallback) == "function", "need successCallback");
|
||||
assert(typeof(errorCallback) == "function", "need errorCallback");
|
||||
|
||||
#ifdef MOZ_MAILNEWS_OAUTH2
|
||||
// Servers that we know enough that they support OAuth2 do not need guessing.
|
||||
if (resultConfig.incoming.auth == Ci.nsMsgAuthMethod.OAuth2) {
|
||||
successCallback(resultConfig);
|
||||
return null;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!resultConfig)
|
||||
resultConfig = new AccountConfig();
|
||||
|
|
|
|||
|
|
@ -95,7 +95,10 @@ function readFromXML(clientConfigXML)
|
|||
"secure" : Ci.nsMsgAuthMethod.passwordEncrypted,
|
||||
"GSSAPI" : Ci.nsMsgAuthMethod.GSSAPI,
|
||||
"NTLM" : Ci.nsMsgAuthMethod.NTLM,
|
||||
"OAuth2" : Ci.nsMsgAuthMethod.OAuth2 });
|
||||
#ifdef MOZ_MAILNEWS_OAUTH2
|
||||
"OAuth2" : Ci.nsMsgAuthMethod.OAuth2
|
||||
#endif
|
||||
});
|
||||
break; // take first that we support
|
||||
} catch (e) { exception = e; }
|
||||
}
|
||||
|
|
@ -176,7 +179,9 @@ function readFromXML(clientConfigXML)
|
|||
"secure" : Ci.nsMsgAuthMethod.passwordEncrypted,
|
||||
"GSSAPI" : Ci.nsMsgAuthMethod.GSSAPI,
|
||||
"NTLM" : Ci.nsMsgAuthMethod.NTLM,
|
||||
#ifdef MOZ_MAILNEWS_OAUTH2
|
||||
"OAuth2" : Ci.nsMsgAuthMethod.OAuth2,
|
||||
#endif
|
||||
});
|
||||
|
||||
break; // take first that we support
|
||||
|
|
|
|||
|
|
@ -30,7 +30,9 @@
|
|||
*/
|
||||
|
||||
Components.utils.import("resource:///modules/mailServices.js");
|
||||
#ifdef MOZ_MAILNEWS_OAUTH2
|
||||
Components.utils.import("resource://gre/modules/OAuth2Providers.jsm");
|
||||
#endif
|
||||
|
||||
if (typeof gEmailWizardLogger == "undefined") {
|
||||
Cu.import("resource:///modules/gloda/log4moz.js");
|
||||
|
|
@ -74,6 +76,7 @@ function verifyConfig(config, alter, msgWindow, successCallback, errorCallback)
|
|||
config.incoming.auth);
|
||||
inServer.authMethod = config.incoming.auth;
|
||||
|
||||
#ifdef MOZ_MAILNEWS_OAUTH2
|
||||
try {
|
||||
// Lookup issuer if needed.
|
||||
if (config.incoming.auth == Ci.nsMsgAuthMethod.OAuth2 ||
|
||||
|
|
@ -100,6 +103,9 @@ function verifyConfig(config, alter, msgWindow, successCallback, errorCallback)
|
|||
|
||||
if (inServer.password ||
|
||||
inServer.authMethod == Ci.nsMsgAuthMethod.OAuth2)
|
||||
#else
|
||||
if (inServer.password)
|
||||
#endif
|
||||
verifyLogon(config, inServer, alter, msgWindow,
|
||||
successCallback, errorCallback);
|
||||
else {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,9 @@ function onInit(aPageId, aServerId)
|
|||
setupImapDeleteUI(aServerId);
|
||||
|
||||
// TLS Cert (External) and OAuth2 are only supported on IMAP.
|
||||
#ifdef MOZ_MAILNEWS_OAUTH2
|
||||
document.getElementById("authMethod-oauth2").hidden = (serverType != "imap");
|
||||
#endif
|
||||
document.getElementById("authMethod-external").hidden = (serverType != "imap");
|
||||
|
||||
// "STARTTLS, if available" is vulnerable to MITM attacks so we shouldn't
|
||||
|
|
@ -83,7 +85,9 @@ function initServerType()
|
|||
setLabelFromStringBundle("authMethod-kerberos", "authKerberos");
|
||||
setLabelFromStringBundle("authMethod-external", "authExternal");
|
||||
setLabelFromStringBundle("authMethod-ntlm", "authNTLM");
|
||||
#ifdef MOZ_MAILNEWS_OAUTH2
|
||||
setLabelFromStringBundle("authMethod-oauth2", "authOAuth2");
|
||||
#endif
|
||||
setLabelFromStringBundle("authMethod-anysecure", "authAnySecure");
|
||||
setLabelFromStringBundle("authMethod-any", "authAny");
|
||||
setLabelFromStringBundle("authMethod-password-encrypted",
|
||||
|
|
|
|||
|
|
@ -139,7 +139,9 @@
|
|||
<menuitem id="authMethod-kerberos" value="5"/>
|
||||
<menuitem id="authMethod-ntlm" value="6"/>
|
||||
<menuitem id="authMethod-external" value="7"/>
|
||||
#ifdef MOZ_MAILNEWS_OAUTH2
|
||||
<menuitem id="authMethod-oauth2" value="10"/>
|
||||
#endif
|
||||
<menuitem id="authMethod-anysecure" value="8"/>
|
||||
<menuitem id="authMethod-any" value="9"/>
|
||||
</menupopup>
|
||||
|
|
|
|||
|
|
@ -140,9 +140,11 @@ var gSmtpServerListWindow =
|
|||
? "authPasswordCleartextViaSSL"
|
||||
: "authPasswordCleartextInsecurely";
|
||||
break;
|
||||
#ifdef MOZ_MAILNEWS_OAUTH2
|
||||
case AuthMethod.OAuth2:
|
||||
authStr = "authOAuth2";
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
// leave empty
|
||||
Components.utils.reportError("Warning: unknown value for smtpserver... authMethod: " +
|
||||
|
|
|
|||
|
|
@ -53,7 +53,9 @@ function initSmtpSettings(server) {
|
|||
"authPasswordCleartextInsecurely");
|
||||
setLabelFromStringBundle("authMethod-kerberos", "authKerberos");
|
||||
setLabelFromStringBundle("authMethod-ntlm", "authNTLM");
|
||||
#ifdef MOZ_MAILNEWS_OAUTH2
|
||||
setLabelFromStringBundle("authMethod-oauth2", "authOAuth2");
|
||||
#endif
|
||||
setLabelFromStringBundle("authMethod-anysecure", "authAnySecure");
|
||||
setLabelFromStringBundle("authMethod-any", "authAny");
|
||||
|
||||
|
|
|
|||
|
|
@ -103,7 +103,9 @@
|
|||
<menuitem id="authMethod-password-encrypted" value="4"/>
|
||||
<menuitem id="authMethod-kerberos" value="5"/>
|
||||
<menuitem id="authMethod-ntlm" value="6"/>
|
||||
#ifdef MOZ_MAILNEWS_OAUTH2
|
||||
<menuitem id="authMethod-oauth2" value="10"/>
|
||||
#endif
|
||||
<menuitem id="authMethod-anysecure" value="8"/>
|
||||
<menuitem id="authMethod-any" value="9"/>
|
||||
</menupopup>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue