diff --git a/config b/config index d96751ee..8158bf80 100644 --- a/config +++ b/config @@ -33,4 +33,5 @@ # classify_as_big_delete = "1000" # user_agent = "" # remove_source_files = "false" -# skip_dir_strict_match = "false" \ No newline at end of file +# skip_dir_strict_match = "false" +# application_id = "" diff --git a/docs/USAGE.md b/docs/USAGE.md index fbe76673..5cc41254 100644 --- a/docs/USAGE.md +++ b/docs/USAGE.md @@ -286,6 +286,7 @@ The default configuration file is listed below: # user_agent = "" # remove_source_files = "false" # skip_dir_strict_match = "false" +# application_id = "" ``` diff --git a/src/config.d b/src/config.d index fdbfbaef..7ab730f7 100644 --- a/src/config.d +++ b/src/config.d @@ -71,6 +71,9 @@ final class Config boolValues["remove_source_files"] = false; // Strict matching for skip_dir boolValues["skip_dir_strict_match"] = false; + // Allow for a custom Client ID / Application ID to be used to replace the inbuilt default + // This is a config file option ONLY + stringValues["application_id"] = ""; // Determine the users home directory. // Need to avoid using ~ here as expandTilde() below does not interpret correctly when running under init.d or systemd scripts diff --git a/src/onedrive.d b/src/onedrive.d index ad842a58..86a26a42 100644 --- a/src/onedrive.d +++ b/src/onedrive.d @@ -15,15 +15,6 @@ private bool simulateNoRefreshTokenFile = false; private ulong retryAfterValue = 0; private immutable { - // Client Identifier - // Client ID (skilion) - string clientId = "22c49a0d-d21c-4792-aed1-8f163c982546"; - - // Default User Agent configuration - string isvTag = "ISV"; - string companyName = "abraunegg"; - string appTitle = "OneDrive_Client_for_Linux"; - // Personal & Business Queries string authUrl = "https://login.microsoftonline.com/common/oauth2/v2.0/authorize"; string redirectUrl = "https://login.microsoftonline.com/common/oauth2/nativeclient"; @@ -36,10 +27,22 @@ private immutable { } private { - string driveUrl = "https://graph.microsoft.com/v1.0/me/drive"; - string itemByIdUrl = "https://graph.microsoft.com/v1.0/me/drive/items/"; - string itemByPathUrl = "https://graph.microsoft.com/v1.0/me/drive/root:/"; - string driveId = ""; + // Client ID / Application ID (abraunegg) + string clientId = "d50ca740-c83f-4d1b-b616-12c519384f0c"; + + // Default User Agent configuration + string isvTag = "ISV"; + string companyName = "abraunegg"; + // Application name as per Microsoft Azure application registration + string appTitle = "OneDrive Client for Linux"; + + // Default Drive ID + string driveId = ""; + + // Common URL's + string driveUrl = "https://graph.microsoft.com/v1.0/me/drive"; + string itemByIdUrl = "https://graph.microsoft.com/v1.0/me/drive/items/"; + string itemByPathUrl = "https://graph.microsoft.com/v1.0/me/drive/root:/"; } class OneDriveException: Exception @@ -110,8 +113,8 @@ final class OneDriveApi // Configure the User Agent string if (cfg.getValueString("user_agent") == "") { - // Application defaults - // Comply with traffic decoration requirements + // Application User Agent string defaults + // Comply with OneDrive traffic decoration requirements // https://docs.microsoft.com/en-us/sharepoint/dev/general-development/how-to-avoid-getting-throttled-or-blocked-in-sharepoint-online // - Identify as ISV and include Company Name, App Name separated by a pipe character and then adding Version number separated with a slash character // Note: If you've created an application, the recommendation is to register and use AppID and AppTitle @@ -146,6 +149,18 @@ final class OneDriveApi bool init() { + // Update clientId if application_id is set in config file + if (cfg.getValueString("application_id") != "") { + // an application_id is set in config file + clientId = cfg.getValueString("application_id"); + companyName = "custom_application"; + } + + // detail what we are using for applicaion identification + log.vdebug("clientId = ", clientId); + log.vdebug("companyName = ", companyName); + log.vdebug("appTitle = ", appTitle); + try { driveId = cfg.getValueString("drive_id"); if (driveId.length) { @@ -188,7 +203,7 @@ final class OneDriveApi { import std.stdio, std.regex; char[] response; - string url = authUrl ~ "?client_id=" ~ clientId ~ "&scope=Files.ReadWrite%20Files.ReadWrite.all%20Sites.ReadWrite.All%20offline_access&response_type=code&redirect_uri=" ~ redirectUrl; + string url = authUrl ~ "?client_id=" ~ clientId ~ "&scope=Files.ReadWrite%20Files.ReadWrite.all%20Sites.Read.All%20Sites.ReadWrite.All%20offline_access&response_type=code&redirect_uri=" ~ redirectUrl; string authFilesString = cfg.getValueString("auth_files"); if (authFilesString == "") { log.log("Authorize this app visiting:\n"); diff --git a/src/sync.d b/src/sync.d index 80912fce..4d6f149e 100644 --- a/src/sync.d +++ b/src/sync.d @@ -290,7 +290,7 @@ final class SyncEngine if (e.httpStatusCode == 401) { // HTTP request returned status code 401 (Unauthorized) log.error("\nERROR: OneDrive returned a 'HTTP 401 Unauthorized' - Cannot Initialize Sync Engine"); - log.error("ERROR: Check your configuration as your access token may be empty or invalid\n"); + log.error("ERROR: Check your configuration as your refresh_token may be empty or invalid. You may need to issue a --logout and re-authorise this client.\n"); // Must exit here exit(-1); } @@ -329,7 +329,7 @@ final class SyncEngine if (e.httpStatusCode == 401) { // HTTP request returned status code 401 (Unauthorized) log.error("\nERROR: OneDrive returned a 'HTTP 401 Unauthorized' - Cannot Initialize Sync Engine"); - log.error("ERROR: Check your configuration as your access token may be empty or invalid\n"); + log.error("ERROR: Check your configuration as your refresh_token may be empty or invalid. You may need to issue a --logout and re-authorise this client.\n"); // Must exit here exit(-1); }