mirror of
https://github.com/abraunegg/onedrive
synced 2024-05-01 13:42:53 +02:00
added --print-token
This commit is contained in:
parent
80c60beef9
commit
3d8daa086d
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue