mirror of
https://github.com/abraunegg/onedrive
synced 2024-05-03 14:33:16 +02:00
Add --reauth to allow easy re-authentication of the client (#1867)
* Add --reauth to allow easy re-authentication of the client
This commit is contained in:
parent
21736f4029
commit
d68c27fb4f
|
@ -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
|
||||
|
|
|
@ -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.'
|
||||
|
|
|
@ -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 -/'
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -196,6 +196,7 @@ docker run $firstRun --restart unless-stopped --name onedrive -v onedrive_conf:/
|
|||
| <B>ONEDRIVE_RESYNC</B> | Controls "--resync" switch on onedrive sync. Default is 0 | 1 |
|
||||
| <B>ONEDRIVE_DOWNLOADONLY</B> | Controls "--download-only" switch on onedrive sync. Default is 0 | 1 |
|
||||
| <B>ONEDRIVE_LOGOUT</B> | Controls "--logout" switch. Default is 0 | 1 |
|
||||
| <B>ONEDRIVE_REAUTH</B> | Controls "--reauth" switch. Default is 0 | 1 |
|
||||
| <B>ONEDRIVE_AUTHFILES</B> | Controls "--auth-files" option. Default is "" | "authUrl:responseUrl" |
|
||||
| <B>ONEDRIVE_AUTHRESPONSE</B> | 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) |
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"],
|
||||
|
|
17
src/main.d
17
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) {
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
12
src/sync.d
12
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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue