From 6f768a33825fa3c5c6402fe8c8ba4e4c670b49d9 Mon Sep 17 00:00:00 2001 From: techknowlogick <techknowlogick@gitea.com> Date: Fri, 28 Feb 2025 02:00:20 -0500 Subject: [PATCH] refresh oauth token in git cred helper func --- cmd/login/helper.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cmd/login/helper.go b/cmd/login/helper.go index fd6d88d..511f420 100644 --- a/cmd/login/helper.go +++ b/cmd/login/helper.go @@ -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