Update application output when just authorising application (Issue #820) (#821)

* Update application output to be clearer when just authorising the application and --synchronize or --monitor not passed in
* Update usage.md with updated authorize details and example
This commit is contained in:
abraunegg 2020-03-15 06:29:44 +11:00 committed by GitHub
parent 63ce6a7d10
commit b1fcb814c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 12 deletions

View file

@ -29,10 +29,10 @@ The application will attempt to handle instances where you have two files with t
### curl compatibility
If your system utilises curl >= 7.62.0 curl defaults to prefer HTTP/2 over HTTP/1.1 by default. If you wish to use HTTP/2 for some operations you will need to use the `--force-http-2` config option to enable otherwise all operations will use HTTP/1.1.
### First run :zap:
After installing the application you must run it at least once from the terminal to authorize it.
### Authorize the application with your OneDrive Account
After installing the application you must authorize the application with your OneDrive Account. This is done by running the application without any additional command switches.
You will be asked to open a specific link using your web browser where you will have to login into your Microsoft Account and give the application the permission to access your files. After giving the permission, you will be redirected to a blank page. Copy the URI of the blank page into the application.
You will be asked to open a specific URL by using your web browser where you will have to login into your Microsoft Account and give the application the permission to access your files. After giving permission to the application, you will be redirected to a blank page. Copy the URI of the blank page into the application.
```text
[user@hostname ~]$ onedrive
@ -44,6 +44,20 @@ Enter the response uri:
```
**Example:**
```
[user@hostname ~]$ onedrive
Authorize this app visiting:
https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=22c49a0d-d21c-4792-aed1-8f163c982546&scope=Files.ReadWrite%20Files.ReadWrite.all%20Sites.ReadWrite.All%20offline_access&response_type=code&redirect_uri=https://login.microsoftonline.com/common/oauth2/nativeclient
Enter the response uri: https://login.microsoftonline.com/common/oauth2/nativeclient?code=<redacted>
Application has been successfully authorised, however no additional command switches were provided.
Please use --help for further assistance in regards to running this application.
```
### Show your configuration
To validate your configuration the application will use, utilize the following:
```text

View file

@ -20,6 +20,8 @@ final class Config
public string configFileSyncDir;
public string configFileSkipFile;
public string configFileSkipDir;
// was the application just authorised - paste of response uri
public bool applicationAuthorizeResponseUri = false;
private string userConfigFilePath;
// hashmap for the values found in the user config file
@ -31,7 +33,8 @@ final class Config
this(string confdirOption)
{
// default configuration
// default configuration - entries in config file ~/.config/onedrive/config
// an entry here means it can be set via the config file if there is a coresponding read and set in update_from_args()
stringValues["sync_dir"] = defaultSyncDir;
stringValues["skip_file"] = defaultSkipFile;
stringValues["skip_dir"] = defaultSkipDir;

View file

@ -413,7 +413,8 @@ int main(string[] args)
log.log("NOTE: The use of --force-http-1.1 is depreciated");
}
log.vlog("Initializing the OneDrive API ...");
// Test if OneDrive service can be reached
log.vdebug("Testing network to ensure network connectivity to Microsoft OneDrive Service");
try {
online = testNetwork();
} catch (CurlException e) {
@ -424,8 +425,9 @@ int main(string[] args)
return EXIT_FAILURE;
}
}
// Initialize OneDrive, check for authorization
log.vlog("Initializing the OneDrive API ...");
oneDrive = new OneDriveApi(cfg);
oneDrive.printAccessToken = cfg.getValueBool("print_token");
if (!oneDrive.init()) {
@ -435,9 +437,8 @@ int main(string[] args)
return EXIT_UNAUTHORIZED;
}
// if --synchronize or --monitor not passed in, exit & display help
// if --synchronize or --monitor not passed in, configure the flag to display help & exit
auto performSyncOK = false;
if (cfg.getValueBool("synchronize") || cfg.getValueBool("monitor")) {
performSyncOK = true;
}
@ -449,10 +450,20 @@ int main(string[] args)
}
if (!performSyncOK) {
writeln("\n--synchronize or --monitor missing from your command options or use --help for further assistance\n");
writeln("No OneDrive sync will be performed without either of these two arguments being present\n");
oneDrive.http.shutdown();
return EXIT_FAILURE;
// was the application just authorised?
if (cfg.applicationAuthorizeResponseUri) {
// Application was just authorised
log.log("\nApplication has been successfully authorised, however no additional command switches were provided.\n");
log.log("Please use --help for further assistance in regards to running this application.\n");
oneDrive.http.shutdown();
return EXIT_SUCCESS;
} else {
// Application was not just authorised
log.log("\n--synchronize or --monitor switches missing from your command line input. Please add one (not both) of these switches to your command line or use --help for further assistance.\n");
log.log("No OneDrive sync will be performed without one of these two arguments being present.\n");
oneDrive.http.shutdown();
return EXIT_FAILURE;
}
}
// if --synchronize && --monitor passed in, exit & display help as these conflict with each other

View file

@ -180,6 +180,7 @@ final class OneDriveApi
log.log("Authorize this app visiting:\n");
write(url, "\n\n", "Enter the response uri: ");
readln(response);
cfg.applicationAuthorizeResponseUri = true;
} else {
string[] authFiles = authFilesString.split(":");
string authUrl = authFiles[0];