mirror of
https://github.com/abraunegg/onedrive
synced 2024-05-17 21:26:41 +02:00
* 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
This commit is contained in:
parent
2d450a3a8f
commit
6f85d539da
3
config
3
config
|
@ -33,4 +33,5 @@
|
||||||
# classify_as_big_delete = "1000"
|
# classify_as_big_delete = "1000"
|
||||||
# user_agent = ""
|
# user_agent = ""
|
||||||
# remove_source_files = "false"
|
# remove_source_files = "false"
|
||||||
# skip_dir_strict_match = "false"
|
# skip_dir_strict_match = "false"
|
||||||
|
# application_id = ""
|
||||||
|
|
|
@ -286,6 +286,7 @@ The default configuration file is listed below:
|
||||||
# user_agent = ""
|
# user_agent = ""
|
||||||
# remove_source_files = "false"
|
# remove_source_files = "false"
|
||||||
# skip_dir_strict_match = "false"
|
# skip_dir_strict_match = "false"
|
||||||
|
# application_id = ""
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,9 @@ final class Config
|
||||||
boolValues["remove_source_files"] = false;
|
boolValues["remove_source_files"] = false;
|
||||||
// Strict matching for skip_dir
|
// Strict matching for skip_dir
|
||||||
boolValues["skip_dir_strict_match"] = false;
|
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.
|
// 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
|
// Need to avoid using ~ here as expandTilde() below does not interpret correctly when running under init.d or systemd scripts
|
||||||
|
|
|
@ -15,15 +15,6 @@ private bool simulateNoRefreshTokenFile = false;
|
||||||
private ulong retryAfterValue = 0;
|
private ulong retryAfterValue = 0;
|
||||||
|
|
||||||
private immutable {
|
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
|
// Personal & Business Queries
|
||||||
string authUrl = "https://login.microsoftonline.com/common/oauth2/v2.0/authorize";
|
string authUrl = "https://login.microsoftonline.com/common/oauth2/v2.0/authorize";
|
||||||
string redirectUrl = "https://login.microsoftonline.com/common/oauth2/nativeclient";
|
string redirectUrl = "https://login.microsoftonline.com/common/oauth2/nativeclient";
|
||||||
|
@ -36,10 +27,22 @@ private immutable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private {
|
private {
|
||||||
string driveUrl = "https://graph.microsoft.com/v1.0/me/drive";
|
// Client ID / Application ID (abraunegg)
|
||||||
string itemByIdUrl = "https://graph.microsoft.com/v1.0/me/drive/items/";
|
string clientId = "d50ca740-c83f-4d1b-b616-12c519384f0c";
|
||||||
string itemByPathUrl = "https://graph.microsoft.com/v1.0/me/drive/root:/";
|
|
||||||
string driveId = "";
|
// 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
|
class OneDriveException: Exception
|
||||||
|
@ -110,8 +113,8 @@ final class OneDriveApi
|
||||||
|
|
||||||
// Configure the User Agent string
|
// Configure the User Agent string
|
||||||
if (cfg.getValueString("user_agent") == "") {
|
if (cfg.getValueString("user_agent") == "") {
|
||||||
// Application defaults
|
// Application User Agent string defaults
|
||||||
// Comply with traffic decoration requirements
|
// 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
|
// 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
|
// - 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
|
// 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()
|
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 {
|
try {
|
||||||
driveId = cfg.getValueString("drive_id");
|
driveId = cfg.getValueString("drive_id");
|
||||||
if (driveId.length) {
|
if (driveId.length) {
|
||||||
|
@ -188,7 +203,7 @@ final class OneDriveApi
|
||||||
{
|
{
|
||||||
import std.stdio, std.regex;
|
import std.stdio, std.regex;
|
||||||
char[] response;
|
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");
|
string authFilesString = cfg.getValueString("auth_files");
|
||||||
if (authFilesString == "") {
|
if (authFilesString == "") {
|
||||||
log.log("Authorize this app visiting:\n");
|
log.log("Authorize this app visiting:\n");
|
||||||
|
|
|
@ -290,7 +290,7 @@ final class SyncEngine
|
||||||
if (e.httpStatusCode == 401) {
|
if (e.httpStatusCode == 401) {
|
||||||
// HTTP request returned status code 401 (Unauthorized)
|
// HTTP request returned status code 401 (Unauthorized)
|
||||||
log.error("\nERROR: OneDrive returned a 'HTTP 401 Unauthorized' - Cannot Initialize Sync Engine");
|
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
|
// Must exit here
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
@ -329,7 +329,7 @@ final class SyncEngine
|
||||||
if (e.httpStatusCode == 401) {
|
if (e.httpStatusCode == 401) {
|
||||||
// HTTP request returned status code 401 (Unauthorized)
|
// HTTP request returned status code 401 (Unauthorized)
|
||||||
log.error("\nERROR: OneDrive returned a 'HTTP 401 Unauthorized' - Cannot Initialize Sync Engine");
|
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
|
// Must exit here
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue