From 8797dfb9e09607ecaf6f0534ee9b5f3b69a529ec Mon Sep 17 00:00:00 2001 From: Erik <81354428+x64x2@users.noreply.github.com> Date: Mon, 13 Jul 2026 03:53:47 +0000 Subject: [PATCH 1/2] feat:added OAuth2 with token persistence Signed-off-by: Erik <81354428+x64x2@users.noreply.github.com> --- internal/http/client.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/internal/http/client.go b/internal/http/client.go index db491470..6fec78cb 100644 --- a/internal/http/client.go +++ b/internal/http/client.go @@ -34,6 +34,38 @@ func InitClientWithProfile(cfg *ini.File, profileOverride string) { // Init API client if runtime.GOARCH == "wasm" && runtime.GOOS == "js" { + +// Client wraps the OAuth2 client with token persistence +func (RefreshableClient)(ctx context.Context, token *oauth2.Token) *http.Client { + // TokenSource automatically refreshes expired tokens + tokenSource := oauthConfig.TokenSource(ctx, token) + savingSource := &SavingTokenSource{ + source: tokenSource, + store: tokenStore, + } + + return oauth2.NewClient(ctx, savingSource) +} + +// SavingTokenSource saves the token whenever it gets refreshed +type SavingTokenSource struct { + source oauth2.TokenSource + store *TokenStore +} + +func (s *SavingTokenSource) Token() (*oauth2.Token, error) { + token, err := s.source.Token() + if err != nil { + return nil, err + } + + // Save the potentially refreshed token + if err := s.store.Save(token); err != nil { + log.Printf("Warning: failed to save token: %v", err) + } + + return token, nil +} // In WASM mode, we use an unauthenticated client Client = &ovh.Client{ Client: &http.Client{}, From 610084bfbfabc6e836134c2a97543baec685eab5 Mon Sep 17 00:00:00 2001 From: Erik <81354428+x64x2@users.noreply.github.com> Date: Mon, 13 Jul 2026 04:10:19 +0000 Subject: [PATCH 2/2] Update client.go Signed-off-by: Erik <81354428+x64x2@users.noreply.github.com> --- internal/http/client.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/http/client.go b/internal/http/client.go index 6fec78cb..c3a8a862 100644 --- a/internal/http/client.go +++ b/internal/http/client.go @@ -20,6 +20,8 @@ import ( "golang.org/x/sync/errgroup" "golang.org/x/sync/semaphore" "gopkg.in/ini.v1" + "golang.org/x/oauth2" + "golang.org/x/oauth2/github ) // OVH API client