From 3d8daa086dc47a062cb526ed875c97caee529b7b Mon Sep 17 00:00:00 2001 From: skilion Date: Sun, 28 May 2017 20:14:50 +0200 Subject: [PATCH] added --print-token --- src/main.d | 6 +++++- src/onedrive.d | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main.d b/src/main.d index 0de12d25..26dfef8e 100644 --- a/src/main.d +++ b/src/main.d @@ -16,6 +16,8 @@ int main(string[] args) bool logout; // enable verbose logging bool verbose; + // print the access token + bool printAccessToken; try { auto opt = getopt( @@ -25,7 +27,8 @@ int main(string[] args) "resync", "Forget the last saved state, perform a full sync.", &resync, "logout", "Logout the current user.", &logout, "confdir", "Set the directory to use to store the configuration files.", &configDirName, - "verbose|v", "Print more details, useful for debugging.", &log.verbose + "verbose|v", "Print more details, useful for debugging.", &log.verbose, + "print-token", "Print the access token, useful for debugging.", &printAccessToken ); if (opt.helpWanted) { defaultGetoptPrinter( @@ -71,6 +74,7 @@ int main(string[] args) return EXIT_FAILURE; } auto onedrive = new OneDriveApi(cfg); + onedrive.printAccessToken = printAccessToken; if (!onedrive.init()) { log.log("Could not initialize the OneDrive API"); // workaround for segfault in std.net.curl.Curl.shutdown() on exit diff --git a/src/onedrive.d b/src/onedrive.d index b400f2b9..dec6126f 100644 --- a/src/onedrive.d +++ b/src/onedrive.d @@ -50,6 +50,9 @@ final class OneDriveApi private SysTime accessTokenExpiration; /* private */ HTTP http; + // if true, every new access token is printed + bool printAccessToken; + this(Config cfg) { this.cfg = cfg; @@ -244,6 +247,7 @@ final class OneDriveApi refreshToken = response["refresh_token"].str(); accessTokenExpiration = Clock.currTime() + dur!"seconds"(response["expires_in"].integer()); std.file.write(cfg.refreshTokenFilePath, refreshToken); + if (printAccessToken) writeln("New access token: ", accessToken); } private void checkAccessTokenExpired()