Skip to content

Commit

Permalink
O365: prepare GCC-High/DoD endpoints support, move outlook login url …
Browse files Browse the repository at this point in the history
…references to Settings

git-svn-id: https://svn.code.sf.net/p/davmail/code/trunk@3505 3d1905a2-6b24-0410-a738-b14d5a86fcbd
  • Loading branch information
mguessan committed Jan 5, 2024
1 parent 10e6326 commit a174cdb
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 9 deletions.
11 changes: 11 additions & 0 deletions src/java/davmail/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public final class Settings {

public static final String OUTLOOK_URL = "https://outlook.office365.com";
public static final String O365_URL = OUTLOOK_URL+"/EWS/Exchange.asmx";
public static final String O365_LOGIN_URL = "https://login.microsoftonline.com/";

public static final String O365 = "O365";
public static final String O365_MODERN = "O365Modern";
public static final String O365_INTERACTIVE = "O365Interactive";
Expand Down Expand Up @@ -759,4 +761,13 @@ public static String getO365Url() {
return "https://outlook.office365."+tld+"/EWS/Exchange.asmx";
}
}

public static String getO365LoginUrl() {
String tld = getProperty("davmail.tld");
if (tld == null) {
return O365_LOGIN_URL;
} else {
return "https://login.microsoftonline."+tld+"/";
}
}
}
8 changes: 4 additions & 4 deletions src/java/davmail/exchange/auth/O365Authenticator.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void authenticate() throws IOException {
// common DavMail client id
String clientId = Settings.getProperty("davmail.oauth.clientId", "facd6cff-a294-4415-b59f-c5b01937d7bd");
// standard native app redirectUri
String redirectUri = Settings.getProperty("davmail.oauth.redirectUri", "https://login.microsoftonline.com/common/oauth2/nativeclient");
String redirectUri = Settings.getProperty("davmail.oauth.redirectUri", Settings.O365_LOGIN_URL+"common/oauth2/nativeclient");
// company tenantId or common
tenantId = Settings.getProperty("davmail.oauth.tenantId", "common");

Expand Down Expand Up @@ -154,7 +154,7 @@ public void authenticate() throws IOException {

String referer = getRequest.getURI().toString();

RestRequest getCredentialMethod = new RestRequest("https://login.microsoftonline.com/" + tenantId + "/GetCredentialType");
RestRequest getCredentialMethod = new RestRequest(Settings.getO365LoginUrl() + tenantId + "/GetCredentialType");
getCredentialMethod.setRequestHeader("Accept", "application/json");
getCredentialMethod.setRequestHeader("canary", apiCanary);
getCredentialMethod.setRequestHeader("client-request-id", clientRequestId);
Expand Down Expand Up @@ -186,7 +186,7 @@ public void authenticate() throws IOException {
LOGGER.debug("Detected ADFS, redirecting to " + federationRedirectUrl);
code = authenticateRedirectADFS(httpClientAdapter, federationRedirectUrl, url);
} else {
PostRequest logonMethod = new PostRequest("https://login.microsoftonline.com/" + tenantId + "/login");
PostRequest logonMethod = new PostRequest(Settings.getO365LoginUrl() + tenantId + "/login");
logonMethod.setRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
logonMethod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

Expand Down Expand Up @@ -374,7 +374,7 @@ private URI handleMfa(HttpClientAdapter httpClientAdapter, PostRequest logonMeth
String urlBeginAuth = config.getString("urlBeginAuth");
String urlEndAuth = config.getString("urlEndAuth");
// Get processAuth url from config
String urlProcessAuth = config.optString("urlPost", "https://login.microsoftonline.com/" + tenantId + "/SAS/ProcessAuth");
String urlProcessAuth = config.optString("urlPost", Settings.getO365LoginUrl() + tenantId + "/SAS/ProcessAuth");

boolean isMFAMethodSupported = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void authenticate() throws IOException {
// common DavMail client id
final String clientId = Settings.getProperty("davmail.oauth.clientId", "facd6cff-a294-4415-b59f-c5b01937d7bd");
// standard native app redirectUri
final String redirectUri = Settings.getProperty("davmail.oauth.redirectUri", "https://login.microsoftonline.com/common/oauth2/nativeclient");
final String redirectUri = Settings.getProperty("davmail.oauth.redirectUri", Settings.O365_LOGIN_URL+"common/oauth2/nativeclient");
// company tenantId or common
String tenantId = Settings.getProperty("davmail.oauth.tenantId", "common");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void authenticate() throws IOException {
// common DavMail client id
final String clientId = Settings.getProperty("davmail.oauth.clientId", "facd6cff-a294-4415-b59f-c5b01937d7bd");
// standard native app redirectUri
final String redirectUri = Settings.getProperty("davmail.oauth.redirectUri", "https://login.microsoftonline.com/common/oauth2/nativeclient");
final String redirectUri = Settings.getProperty("davmail.oauth.redirectUri", Settings.O365_LOGIN_URL+"common/oauth2/nativeclient");
// company tenantId or common
String tenantId = Settings.getProperty("davmail.oauth.tenantId", "common");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void authenticate() throws IOException {
// common DavMail client id
final String clientId = Settings.getProperty("davmail.oauth.clientId", "facd6cff-a294-4415-b59f-c5b01937d7bd");
// standard native app redirectUri
final String redirectUri = Settings.getProperty("davmail.oauth.redirectUri", "https://login.microsoftonline.com/common/oauth2/nativeclient");
final String redirectUri = Settings.getProperty("davmail.oauth.redirectUri", Settings.O365_LOGIN_URL+"common/oauth2/nativeclient");
// company tenantId or common
String tenantId = Settings.getProperty("davmail.oauth.tenantId", "common");

Expand Down
4 changes: 2 additions & 2 deletions src/java/davmail/exchange/auth/O365Token.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ public class O365Token {
public O365Token(String tenantId, String clientId, String redirectUri, String password) {
this.clientId = clientId;
this.redirectUri = redirectUri;
this.tokenUrl = "https://login.microsoftonline.com/" + tenantId + "/oauth2/token";
this.tokenUrl = Settings.getO365LoginUrl() + tenantId + "/oauth2/token";
this.password = password;
}

public O365Token(String tenantId, String clientId, String redirectUri, String code, String password) throws IOException {
this.clientId = clientId;
this.redirectUri = redirectUri;
this.tokenUrl = "https://login.microsoftonline.com/" + tenantId + "/oauth2/token";
this.tokenUrl = Settings.getO365Url() + tenantId + "/oauth2/token";
this.password = password;

ArrayList<NameValuePair> parameters = new ArrayList<>();
Expand Down

0 comments on commit a174cdb

Please sign in to comment.