Fix oauth2 not displaying the new token
authorMikael Berthe <mikael@lilotux.net>
Sun, 13 Jan 2019 12:58:50 +0100
changeset 245 910f00ab2799
parent 244 a01bc98ae01a
child 246 0998f404dd31
Fix oauth2 not displaying the new token If the configuration file contains an old token, this token was displayed after an oauth2 renewal instead of the new one.
cmd/config.go
cmd/oauth2.go
--- a/cmd/config.go	Sun Jan 13 12:33:24 2019 +0100
+++ b/cmd/config.go	Sun Jan 13 12:58:50 2019 +0100
@@ -84,20 +84,23 @@
 ...
 `
 
-func configDump(force bool) error {
-	if !force && viper.GetBool("safe_mode") {
-		errPrint("Cannot dump: disabled by configuration (safe_mode)")
-		return nil
-	}
+func configDump(oauth2 bool) error {
+	if !oauth2 {
+		if viper.GetBool("safe_mode") {
+			errPrint("Cannot dump: disabled by configuration (safe_mode)")
+			return nil
+		}
 
-	if err := madonInitClient(); err != nil {
-		return err
-	}
-	// Try to sign in if a login was provided
-	if viper.GetString("token") != "" || viper.GetString("login") != "" {
-		if err := madonLogin(); err != nil {
-			errPrint("Error: could not log in: %v", err)
-			os.Exit(-1)
+		if err := madonInitClient(); err != nil {
+			return err
+		}
+
+		// Try to sign in if a login was provided
+		if viper.GetString("token") != "" || viper.GetString("login") != "" {
+			if err := madonLogin(); err != nil {
+				errPrint("Error: could not log in: %v", err)
+				os.Exit(-1)
+			}
 		}
 	}
 
--- a/cmd/oauth2.go	Sun Jan 13 12:33:24 2019 +0100
+++ b/cmd/oauth2.go	Sun Jan 13 12:58:50 2019 +0100
@@ -88,6 +88,7 @@
 
 	if gClient.UserToken != nil {
 		errPrint("Login successful.\n")
+		errPrint("The new token is %s.\n", gClient.UserToken.AccessToken)
 		configDump(true)
 	}
 	return nil