Switch to OAuth parameters

pull/207/head
M66B 4 years ago
parent 83731d082e
commit b001d53bc2

@ -277,6 +277,7 @@ public class EmailProvider implements Parcelable {
provider.oauth.scopes = xml.getAttributeValue(null, "scopes").split(","); provider.oauth.scopes = xml.getAttributeValue(null, "scopes").split(",");
provider.oauth.authorizationEndpoint = xml.getAttributeValue(null, "authorizationEndpoint"); provider.oauth.authorizationEndpoint = xml.getAttributeValue(null, "authorizationEndpoint");
provider.oauth.tokenEndpoint = xml.getAttributeValue(null, "tokenEndpoint"); provider.oauth.tokenEndpoint = xml.getAttributeValue(null, "tokenEndpoint");
provider.oauth.tokenScopes = getAttributeBooleanValue(xml, "tokenScopes", false);
provider.oauth.redirectUri = xml.getAttributeValue(null, "redirectUri"); provider.oauth.redirectUri = xml.getAttributeValue(null, "redirectUri");
provider.oauth.privacy = xml.getAttributeValue(null, "privacy"); provider.oauth.privacy = xml.getAttributeValue(null, "privacy");
provider.oauth.prompt = xml.getAttributeValue(null, "prompt"); provider.oauth.prompt = xml.getAttributeValue(null, "prompt");
@ -1287,6 +1288,7 @@ public class EmailProvider implements Parcelable {
String[] scopes; String[] scopes;
String authorizationEndpoint; String authorizationEndpoint;
String tokenEndpoint; String tokenEndpoint;
boolean tokenScopes;
String redirectUri; String redirectUri;
String privacy; String privacy;
String prompt; String prompt;

@ -372,17 +372,6 @@ public class FragmentOAuth extends FragmentBase {
for (String key : provider.oauth.parameters.keySet()) for (String key : provider.oauth.parameters.keySet())
params.put(key, provider.oauth.parameters.get(key)); params.put(key, provider.oauth.parameters.get(key));
if ("gmail".equals(provider.id))
params.put("access_type", "offline");
if ("yandex".equals(provider.id)) {
params.put("device_name", "Android/FairEmail");
params.put("force_confirm", "true");
}
if ("mailru".equals(provider.id))
params.put("prompt_force", "1");
AuthorizationRequest.Builder authRequestBuilder = AuthorizationRequest.Builder authRequestBuilder =
new AuthorizationRequest.Builder( new AuthorizationRequest.Builder(
serviceConfig, serviceConfig,
@ -408,14 +397,6 @@ public class FragmentOAuth extends FragmentBase {
if (!TextUtils.isEmpty(provider.oauth.prompt)) if (!TextUtils.isEmpty(provider.oauth.prompt))
authRequestBuilder.setPrompt(provider.oauth.prompt); authRequestBuilder.setPrompt(provider.oauth.prompt);
// For offline access
if ("gmail".equals(provider.id))
authRequestBuilder.setPrompt("consent");
// https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow
if (isOutlook(provider.id))
authRequestBuilder.setPrompt("select_account");
AuthorizationRequest authRequest = authRequestBuilder.build(); AuthorizationRequest authRequest = authRequestBuilder.build();
EntityLog.log(context, "OAuth request provider=" + provider.id + " uri=" + authRequest.toUri()); EntityLog.log(context, "OAuth request provider=" + provider.id + " uri=" + authRequest.toUri());
@ -478,7 +459,7 @@ public class FragmentOAuth extends FragmentBase {
.setAdditionalParameters(Collections.<String, String>emptyMap()) .setAdditionalParameters(Collections.<String, String>emptyMap())
.setNonce(auth.request.nonce); .setNonce(auth.request.nonce);
if (isOutlook(provider.id)) if (provider.oauth.tokenScopes)
builder.setScope(TextUtils.join(" ", provider.oauth.scopes)); builder.setScope(TextUtils.join(" ", provider.oauth.scopes));
TokenRequest request = builder.build(); TokenRequest request = builder.build();
@ -971,7 +952,7 @@ public class FragmentOAuth extends FragmentBase {
if ("gmail".equals(id)) if ("gmail".equals(id))
tvGmailDraftsHint.setVisibility(View.VISIBLE); tvGmailDraftsHint.setVisibility(View.VISIBLE);
if (isOutlook(id)) { if ("office365".equals(id) || "outlook".equals(id)) {
if (ex instanceof AuthenticationFailedException) if (ex instanceof AuthenticationFailedException)
tvOfficeAuthHint.setVisibility(View.VISIBLE); tvOfficeAuthHint.setVisibility(View.VISIBLE);
} }
@ -1009,8 +990,4 @@ public class FragmentOAuth extends FragmentBase {
tvGmailDraftsHint.setVisibility(View.GONE); tvGmailDraftsHint.setVisibility(View.GONE);
tvOfficeAuthHint.setVisibility(View.GONE); tvOfficeAuthHint.setVisibility(View.GONE);
} }
private static boolean isOutlook(String id) {
return ("office365".equals(id) || "outlook".equals(id));
}
} }

@ -15,6 +15,22 @@
host="smtp.gmail.com" host="smtp.gmail.com"
port="465" port="465"
starttls="false" /> starttls="false" />
<oauth
askAccount="true"
authorizationEndpoint="https://accounts.google.com/o/oauth2/auth"
clientId=""
clientSecret=""
enabled="false"
privacy="https://policies.google.com/privacy"
prompt="consent"
redirectUri="https://oauth.faircode.eu/"
scopes="https://mail.google.com/"
tokenEndpoint="https://oauth2.googleapis.com/token">
<!-- promp=consent offline access -->
<parameter
key="access_type"
value="offline" />
</oauth>
<!-- https://email.faircode.eu/.well-known/assetlinks.json --> <!-- https://email.faircode.eu/.well-known/assetlinks.json -->
<!-- /opt/android-studio/jre/bin/keytool -keystore ~/.android/debug.keystore -list -v --> <!-- /opt/android-studio/jre/bin/keytool -keystore ~/.android/debug.keystore -list -v -->
</provider> </provider>
@ -102,9 +118,12 @@
clientSecret="r=o4@SlzU:MA6MlXM6mPG[44i4gYPq[@" clientSecret="r=o4@SlzU:MA6MlXM6mPG[44i4gYPq[@"
enabled="true" enabled="true"
privacy="https://privacy.microsoft.com/privacystatement" privacy="https://privacy.microsoft.com/privacystatement"
prompt="select_account"
redirectUri="https://oauth.faircode.eu/" redirectUri="https://oauth.faircode.eu/"
scopes="profile,openid,email,offline_access,https://outlook.office.com/IMAP.AccessAsUser.All,https://outlook.office.com/SMTP.Send" scopes="profile,openid,email,offline_access,https://outlook.office.com/IMAP.AccessAsUser.All,https://outlook.office.com/SMTP.Send"
tokenEndpoint="https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token" /> tokenEndpoint="https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token"
tokenScopes="true" />
<!-- https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow -->
<!-- https://docs.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth --> <!-- https://docs.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth -->
</provider> </provider>
<provider <provider
@ -130,9 +149,11 @@
clientSecret="k847Q~ZKtIBNp~ls_riKEbFDsvOQEdUA.YDNt" clientSecret="k847Q~ZKtIBNp~ls_riKEbFDsvOQEdUA.YDNt"
enabled="false" enabled="false"
privacy="https://privacy.microsoft.com/privacystatement" privacy="https://privacy.microsoft.com/privacystatement"
prompt="select_account"
redirectUri="https://oauth.faircode.eu/" redirectUri="https://oauth.faircode.eu/"
scopes="openid,email,offline_access,https://outlook.office.com/IMAP.AccessAsUser.All,https://outlook.office.com/SMTP.Send" scopes="openid,email,offline_access,https://outlook.office.com/IMAP.AccessAsUser.All,https://outlook.office.com/SMTP.Send"
tokenEndpoint="https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token" /> tokenEndpoint="https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token"
tokenScopes="true" />
<!-- https://docs.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth --> <!-- https://docs.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth -->
</provider> </provider>
<!-- needs subscription --> <!-- needs subscription -->
@ -387,7 +408,14 @@
privacy="https://yandex.com/legal/confidential/" privacy="https://yandex.com/legal/confidential/"
redirectUri="https://oauth.faircode.eu/" redirectUri="https://oauth.faircode.eu/"
scopes="mail:imap_full,mail:smtp" scopes="mail:imap_full,mail:smtp"
tokenEndpoint="https://oauth.yandex.com/token" /> tokenEndpoint="https://oauth.yandex.com/token">
<parameter
key="device_name"
value="Android/FairEmail" />
<parameter
key="force_confirm"
value="true" />
</oauth>
</provider> </provider>
<provider <provider
name="web.de" name="web.de"
@ -579,7 +607,11 @@
privacy="https://help.mail.ru/legal/terms/common/privacy" privacy="https://help.mail.ru/legal/terms/common/privacy"
redirectUri="https://oauth.faircode.eu/" redirectUri="https://oauth.faircode.eu/"
scopes="userinfo mail.imap" scopes="userinfo mail.imap"
tokenEndpoint="https://oauth.mail.ru/token" /> tokenEndpoint="https://oauth.mail.ru/token">
<parameter
key="prompt_force"
value="1" />
</oauth>
<!-- https://oauth.mail.ru/docs --> <!-- https://oauth.mail.ru/docs -->
</provider> </provider>
<provider <provider

Loading…
Cancel
Save