refresh oauth token in git cred helper func

This commit is contained in:
techknowlogick 2025-02-28 02:00:20 -05:00
parent c660c83e41
commit 6f768a3382

View File

@ -10,7 +10,9 @@ import (
"net/url"
"os"
"strings"
"time"
"code.gitea.io/tea/modules/auth"
"code.gitea.io/tea/modules/config"
"code.gitea.io/tea/modules/task"
"github.com/urfave/cli/v2"
@ -102,6 +104,14 @@ var CmdLoginHelper = cli.Command{
return err
}
if userConfig.TokenExpiry > 0 && time.Now().Unix() > userConfig.TokenExpiry {
// Token is expired, refresh it
err = auth.RefreshAccessToken(userConfig)
if err != nil {
return err
}
}
_, err = fmt.Fprintf(os.Stdout, "protocol=%s\nhost=%s\nusername=%s\npassword=%s\n", host.Scheme, host.Host, userConfig.User, userConfig.Token)
if err != nil {
return err