diff --git a/contrib/completions/complete.bash b/contrib/completions/complete.bash index c27a86b1..e98149f2 100644 --- a/contrib/completions/complete.bash +++ b/contrib/completions/complete.bash @@ -12,7 +12,7 @@ _onedrive() cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} - options='--check-for-nomount --check-for-nosync --debug-https --disable-notifications --display-config --display-sync-status --download-only --disable-upload-validation --dry-run --enable-logging --force-http-1.1 --force-http-2 --local-first --logout -m --monitor --no-remote-delete --print-token --resync --skip-dot-files --skip-symlinks --synchronize --upload-only -v --verbose --version -h --help' + options='--check-for-nomount --check-for-nosync --debug-https --disable-notifications --display-config --display-sync-status --download-only --disable-upload-validation --dry-run --enable-logging --force-http-1.1 --force-http-2 --local-first --logout -m --monitor --no-remote-delete --print-token --reauth --resync --skip-dot-files --skip-symlinks --synchronize --upload-only -v --verbose --version -h --help' argopts='--create-directory --get-O365-drive-id --operation-timeout --remove-directory --single-directory --source-directory' # Loop on the arguments to manage conflicting options diff --git a/contrib/completions/complete.fish b/contrib/completions/complete.fish index a7c99b13..0bd6da41 100644 --- a/contrib/completions/complete.fish +++ b/contrib/completions/complete.fish @@ -25,6 +25,7 @@ complete -c onedrive -l no-remote-delete -d 'Do not delete local file deletes fr complete -c onedrive -l operation-timeout -d 'Specify the maximum amount of time (in seconds) an operation is allowed to take.' complete -c onedrive -l print-token -d 'Print the access token, useful for debugging.' complete -c onedrive -l remote-directory -d 'Remove a directory on OneDrive - no sync will be performed.' +complete -c onedrive -l reauth -d 'Reauthenticate the client with OneDrive.' complete -c onedrive -l resync -d 'Forget the last saved state, perform a full sync.' complete -c onedrive -l single-directory -d 'Specify a single local directory within the OneDrive root to sync.' complete -c onedrive -l skip-dot-files -d 'Skip dot files and folders from syncing.' diff --git a/contrib/completions/complete.zsh b/contrib/completions/complete.zsh index e0fd7e40..74561bdf 100644 --- a/contrib/completions/complete.zsh +++ b/contrib/completions/complete.zsh @@ -28,6 +28,7 @@ all_opts=( '--no-remote-delete[Do not delete local file deletes from OneDrive when using --upload-only]' '--operation-timeout[Specify the maximum amount of time (in seconds) an operation is allowed to take.]:seconds:' '--print-token[Print the access token, useful for debugging]' + '--reauth[Reauthenticate the client with OneDrive]' '--resync[Forget the last saved state, perform a full sync]' '--remove-directory[Remove a directory on OneDrive - no sync will be performed.]:directory name:' '--single-directory[Specify a single local directory within the OneDrive root to sync.]:source directory:_files -/' diff --git a/contrib/docker/entrypoint.sh b/contrib/docker/entrypoint.sh index f06469c6..2d52d02b 100755 --- a/contrib/docker/entrypoint.sh +++ b/contrib/docker/entrypoint.sh @@ -66,11 +66,18 @@ fi # Tell client to logout based on environment variable if [ "${ONEDRIVE_LOGOUT:=0}" == "1" ]; then - echo "# We are logging out to perform a reauthentication" + echo "# We are logging out" echo "# Adding --logout" ARGS=(--logout ${ARGS[@]}) fi +# Tell client to re-authenticate based on environment variable +if [ "${ONEDRIVE_REAUTH:=0}" == "1" ]; then + echo "# We are logging out to perform a reauthentication" + echo "# Adding --reauth" + ARGS=(--reauth ${ARGS[@]}) +fi + # Tell client to utilize auth files at the provided locations based on environment variable if [ -n "${ONEDRIVE_AUTHFILES:=""}" ]; then echo "# We are using auth files to perform authentication" diff --git a/docs/Docker.md b/docs/Docker.md index bd95135a..5dcb3c48 100644 --- a/docs/Docker.md +++ b/docs/Docker.md @@ -196,6 +196,7 @@ docker run $firstRun --restart unless-stopped --name onedrive -v onedrive_conf:/ | ONEDRIVE_RESYNC | Controls "--resync" switch on onedrive sync. Default is 0 | 1 | | ONEDRIVE_DOWNLOADONLY | Controls "--download-only" switch on onedrive sync. Default is 0 | 1 | | ONEDRIVE_LOGOUT | Controls "--logout" switch. Default is 0 | 1 | +| ONEDRIVE_REAUTH | Controls "--reauth" switch. Default is 0 | 1 | | ONEDRIVE_AUTHFILES | Controls "--auth-files" option. Default is "" | "authUrl:responseUrl" | | ONEDRIVE_AUTHRESPONSE | Controls "--auth-response" option. Default is "" | See [here](https://github.com/abraunegg/onedrive/blob/master/docs/USAGE.md#authorize-the-application-with-your-onedrive-account) | diff --git a/docs/USAGE.md b/docs/USAGE.md index bededb42..3020c724 100644 --- a/docs/USAGE.md +++ b/docs/USAGE.md @@ -301,7 +301,7 @@ ERROR: OneDrive returned a 'HTTP 401 Unauthorized' - Cannot Initialize Sync Engi ``` To re-authorise the client, follow the steps below: 1. If running the client as a service (init.d or systemd), stop the service -2. Run the command `onedrive --logout`. This will clean up the previous authorisation, and will prompt you to re-authorise as per initial configuration. +2. Run the command `onedrive --reauth`. This will clean up the previous authorisation, and will prompt you to re-authorise the client as per initial configuration. 3. Restart the client if running as a service or perform a manual sync The application will now sync with OneDrive with the new credentials. @@ -658,7 +658,7 @@ application_id = "22c49a0d-d21c-4792-aed1-8f163c982546" ``` **Note:** The application will now use the older 'skilion' client identifier, however this may increase your chances of getting a OneDrive 429 error. -**Note:** After changing the 'application_id' you will need to restart any 'onedrive' process you have running, and potentially issue a `--logout` to re-auth the client with this updated application ID. +**Note:** After changing the 'application_id' you will need to restart any 'onedrive' process you have running, and potentially issue a `--reauth` to re-authenticate the client with this updated application ID. ### How to 'skip' directories from syncing? @@ -1106,6 +1106,8 @@ Options: Maximum amount of time (in seconds) an operation is allowed to take --print-token Print the access token, useful for debugging + --reauth + Reauthenticate the client with OneDrive --remove-directory ARG Remove a directory on OneDrive - no sync will be performed. --remove-source-files diff --git a/src/config.d b/src/config.d index 1ee493b0..21534ce2 100644 --- a/src/config.d +++ b/src/config.d @@ -296,6 +296,7 @@ final class Config boolValues["display_sync_status"] = false; boolValues["print_token"] = false; boolValues["logout"] = false; + boolValues["reauth"] = false; boolValues["monitor"] = false; boolValues["synchronize"] = false; boolValues["force"] = false; @@ -408,6 +409,9 @@ final class Config "print-token", "Print the access token, useful for debugging", &boolValues["print_token"], + "reauth", + "Reauthenticate the client with OneDrive", + &boolValues["reauth"], "resync", "Forget the last saved state, perform a full sync", &boolValues["resync"], diff --git a/src/main.d b/src/main.d index 236d9fdc..49b2375f 100644 --- a/src/main.d +++ b/src/main.d @@ -545,7 +545,7 @@ int main(string[] args) cfg.setValueBool("resync", true); } - // Handle --logout as separate item, do not 'resync' on a --logout / reauth + // Handle --logout as separate item, do not 'resync' on a --logout if (cfg.getValueBool("logout")) { log.vdebug("--logout requested"); log.log("Deleting the saved authentication status ..."); @@ -555,10 +555,19 @@ int main(string[] args) // Exit return EXIT_SUCCESS; } - + + // Handle --reauth to re-authenticate the client + if (cfg.getValueBool("reauth")) { + log.vdebug("--reauth requested"); + log.log("Deleting the saved authentication status ... re-authentication requested"); + if (!cfg.getValueBool("dry_run")) { + safeRemove(cfg.refreshTokenFilePath); + } + } + // Handle --resync to remove local files if (cfg.getValueBool("resync")) { - if (cfg.getValueBool("resync")) log.vdebug("--resync requested"); + log.vdebug("--resync requested"); log.log("Deleting the saved application sync status ..."); if (!cfg.getValueBool("dry_run")) { safeRemove(cfg.databaseFilePath); @@ -1374,7 +1383,7 @@ bool initSyncEngine(SyncEngine sync) } catch (OneDriveException e) { if (e.httpStatusCode == 400 || e.httpStatusCode == 401) { // Authorization is invalid - log.log("\nAuthorization token invalid, use --logout to authorize the client again\n"); + log.log("\nAuthorization token invalid, use --reauth to authorize the client again\n"); return false; } if (e.httpStatusCode >= 500) { diff --git a/src/onedrive.d b/src/onedrive.d index 6c351bff..df9f5448 100644 --- a/src/onedrive.d +++ b/src/onedrive.d @@ -547,7 +547,7 @@ final class OneDriveApi } return true; } else { - // --dry-run & --logout + // --dry-run & --reauth return authorize(); } } @@ -1115,9 +1115,9 @@ final class OneDriveApi } catch (OneDriveException e) { if (e.httpStatusCode == 400 || e.httpStatusCode == 401) { // flag error and notify - log.errorAndNotify("\nERROR: Refresh token invalid, use --logout to authorize the client again.\n"); + log.errorAndNotify("\nERROR: Refresh token invalid, use --reauth to authorize the client again.\n"); // set error message - e.msg ~= "\nRefresh token invalid, use --logout to authorize the client again"; + e.msg ~= "\nRefresh token invalid, use --reauth to authorize the client again"; } } } diff --git a/src/sync.d b/src/sync.d index 8af58952..2f714ca1 100644 --- a/src/sync.d +++ b/src/sync.d @@ -320,7 +320,7 @@ final class SyncEngine if (e.httpStatusCode == 401) { // HTTP request returned status code 401 (Unauthorized) displayOneDriveErrorMessage(e.msg, getFunctionName!({})); - log.errorAndNotify("\nERROR: 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"); + log.errorAndNotify("\nERROR: Check your configuration as your refresh_token may be empty or invalid. You may need to issue a --reauth and re-authorise this client.\n"); // Must exit here exit(-1); } @@ -359,7 +359,7 @@ final class SyncEngine if (e.httpStatusCode == 401) { // HTTP request returned status code 401 (Unauthorized) displayOneDriveErrorMessage(e.msg, getFunctionName!({})); - log.errorAndNotify("\nERROR: 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"); + log.errorAndNotify("\nERROR: Check your configuration as your refresh_token may be empty or invalid. You may need to issue a --reauth and re-authorise this client.\n"); // Must exit here exit(-1); } @@ -670,7 +670,7 @@ final class SyncEngine if (e.httpStatusCode == 401) { // HTTP request returned status code 401 (Unauthorized) displayOneDriveErrorMessage(e.msg, getFunctionName!({})); - log.errorAndNotify("\nERROR: 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"); + log.errorAndNotify("\nERROR: Check your configuration as your refresh_token may be empty or invalid. You may need to issue a --reauth and re-authorise this client.\n"); // Must exit here exit(-1); } @@ -864,7 +864,7 @@ final class SyncEngine if (e.httpStatusCode == 401) { // HTTP request returned status code 401 (Unauthorized) displayOneDriveErrorMessage(e.msg, getFunctionName!({})); - log.errorAndNotify("\nERROR: 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"); + log.errorAndNotify("\nERROR: Check your configuration as your refresh_token may be empty or invalid. You may need to issue a --reauth and re-authorise this client.\n"); // Must exit here exit(-1); } @@ -5873,7 +5873,7 @@ final class SyncEngine log.error("ERROR: Query of OneDrive for Office 365 Library Name failed"); if (e.httpStatusCode == 403) { // Forbidden - most likely authentication scope needs to be updated - log.error("ERROR: Authentication scope needs to be updated. Use --logout and re-authenticate client."); + log.error("ERROR: Authentication scope needs to be updated. Use --reauth and re-authenticate client."); return; } // HTTP request returned status code 429 (Too Many Requests) @@ -6748,7 +6748,7 @@ final class SyncEngine if (e.httpStatusCode == 401) { // HTTP request returned status code 401 (Unauthorized) displayOneDriveErrorMessage(e.msg, getFunctionName!({})); - log.errorAndNotify("\nERROR: 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"); + log.errorAndNotify("\nERROR: Check your configuration as your refresh_token may be empty or invalid. You may need to issue a --reauth and re-authorise this client.\n"); // Must exit here exit(-1); }