Skip to content

Commit 6f85d53

Browse files
authored
Update client identifier and auth scopes (Issue #769) (#770)
* Update the client identifier to 'd50ca740-c83f-4d1b-b616-12c519384f0c' * Update User Agent identifier to comply with OneDrive traffic decoration requirements * Provide 'config' file option to modify / update client identifier to override application default
1 parent 2d450a3 commit 6f85d53

File tree

5 files changed

+39
-19
lines changed

5 files changed

+39
-19
lines changed

config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@
3333
# classify_as_big_delete = "1000"
3434
# user_agent = ""
3535
# remove_source_files = "false"
36-
# skip_dir_strict_match = "false"
36+
# skip_dir_strict_match = "false"
37+
# application_id = ""

docs/USAGE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ The default configuration file is listed below:
286286
# user_agent = ""
287287
# remove_source_files = "false"
288288
# skip_dir_strict_match = "false"
289+
# application_id = ""
289290
```
290291

291292

src/config.d

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ final class Config
7171
boolValues["remove_source_files"] = false;
7272
// Strict matching for skip_dir
7373
boolValues["skip_dir_strict_match"] = false;
74+
// Allow for a custom Client ID / Application ID to be used to replace the inbuilt default
75+
// This is a config file option ONLY
76+
stringValues["application_id"] = "";
7477

7578
// Determine the users home directory.
7679
// Need to avoid using ~ here as expandTilde() below does not interpret correctly when running under init.d or systemd scripts

src/onedrive.d

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,6 @@ private bool simulateNoRefreshTokenFile = false;
1515
private ulong retryAfterValue = 0;
1616

1717
private immutable {
18-
// Client Identifier
19-
// Client ID (skilion)
20-
string clientId = "22c49a0d-d21c-4792-aed1-8f163c982546";
21-
22-
// Default User Agent configuration
23-
string isvTag = "ISV";
24-
string companyName = "abraunegg";
25-
string appTitle = "OneDrive_Client_for_Linux";
26-
2718
// Personal & Business Queries
2819
string authUrl = "https://login.microsoftonline.com/common/oauth2/v2.0/authorize";
2920
string redirectUrl = "https://login.microsoftonline.com/common/oauth2/nativeclient";
@@ -36,10 +27,22 @@ private immutable {
3627
}
3728

3829
private {
39-
string driveUrl = "https://graph.microsoft.com/v1.0/me/drive";
40-
string itemByIdUrl = "https://graph.microsoft.com/v1.0/me/drive/items/";
41-
string itemByPathUrl = "https://graph.microsoft.com/v1.0/me/drive/root:/";
42-
string driveId = "";
30+
// Client ID / Application ID (abraunegg)
31+
string clientId = "d50ca740-c83f-4d1b-b616-12c519384f0c";
32+
33+
// Default User Agent configuration
34+
string isvTag = "ISV";
35+
string companyName = "abraunegg";
36+
// Application name as per Microsoft Azure application registration
37+
string appTitle = "OneDrive Client for Linux";
38+
39+
// Default Drive ID
40+
string driveId = "";
41+
42+
// Common URL's
43+
string driveUrl = "https://graph.microsoft.com/v1.0/me/drive";
44+
string itemByIdUrl = "https://graph.microsoft.com/v1.0/me/drive/items/";
45+
string itemByPathUrl = "https://graph.microsoft.com/v1.0/me/drive/root:/";
4346
}
4447

4548
class OneDriveException: Exception
@@ -110,8 +113,8 @@ final class OneDriveApi
110113

111114
// Configure the User Agent string
112115
if (cfg.getValueString("user_agent") == "") {
113-
// Application defaults
114-
// Comply with traffic decoration requirements
116+
// Application User Agent string defaults
117+
// Comply with OneDrive traffic decoration requirements
115118
// https://docs.microsoft.com/en-us/sharepoint/dev/general-development/how-to-avoid-getting-throttled-or-blocked-in-sharepoint-online
116119
// - Identify as ISV and include Company Name, App Name separated by a pipe character and then adding Version number separated with a slash character
117120
// Note: If you've created an application, the recommendation is to register and use AppID and AppTitle
@@ -146,6 +149,18 @@ final class OneDriveApi
146149

147150
bool init()
148151
{
152+
// Update clientId if application_id is set in config file
153+
if (cfg.getValueString("application_id") != "") {
154+
// an application_id is set in config file
155+
clientId = cfg.getValueString("application_id");
156+
companyName = "custom_application";
157+
}
158+
159+
// detail what we are using for applicaion identification
160+
log.vdebug("clientId = ", clientId);
161+
log.vdebug("companyName = ", companyName);
162+
log.vdebug("appTitle = ", appTitle);
163+
149164
try {
150165
driveId = cfg.getValueString("drive_id");
151166
if (driveId.length) {
@@ -188,7 +203,7 @@ final class OneDriveApi
188203
{
189204
import std.stdio, std.regex;
190205
char[] response;
191-
string url = authUrl ~ "?client_id=" ~ clientId ~ "&scope=Files.ReadWrite%20Files.ReadWrite.all%20Sites.ReadWrite.All%20offline_access&response_type=code&redirect_uri=" ~ redirectUrl;
206+
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;
192207
string authFilesString = cfg.getValueString("auth_files");
193208
if (authFilesString == "") {
194209
log.log("Authorize this app visiting:\n");

src/sync.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ final class SyncEngine
290290
if (e.httpStatusCode == 401) {
291291
// HTTP request returned status code 401 (Unauthorized)
292292
log.error("\nERROR: OneDrive returned a 'HTTP 401 Unauthorized' - Cannot Initialize Sync Engine");
293-
log.error("ERROR: Check your configuration as your access token may be empty or invalid\n");
293+
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");
294294
// Must exit here
295295
exit(-1);
296296
}
@@ -329,7 +329,7 @@ final class SyncEngine
329329
if (e.httpStatusCode == 401) {
330330
// HTTP request returned status code 401 (Unauthorized)
331331
log.error("\nERROR: OneDrive returned a 'HTTP 401 Unauthorized' - Cannot Initialize Sync Engine");
332-
log.error("ERROR: Check your configuration as your access token may be empty or invalid\n");
332+
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");
333333
// Must exit here
334334
exit(-1);
335335
}

0 commit comments

Comments
 (0)