Skip to content

Commit

Permalink
FIX: Token Storage
Browse files Browse the repository at this point in the history
Auth tokens are now stored in ~/.decanter/auth.json
  • Loading branch information
p5quared committed Apr 15, 2024
1 parent c9f3a31 commit 69f5340
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions store.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"encoding/json"
"os"
"path"

"golang.org/x/oauth2"
)
Expand All @@ -13,18 +14,25 @@ type FileTokenStore struct {
}

func NewFileTokenStore(filename string) *FileTokenStore {

// Ideally we store tokens in ~/.decanter
path, _ := os.UserHomeDir()

dynamicLocation := path + "/.decanter"
os.MkdirAll(dynamicLocation, 0755)

return &FileTokenStore{
filename: filename,
dir: os.TempDir(), // Wrong.
dir: dynamicLocation,
}
}

func (f FileTokenStore) Load() (oauth2.Token, error) {
return LoadAuthFromFile(f.filename)
return LoadAuthFromFile(path.Join(f.dir, f.filename))
}

func (f FileTokenStore) Save(r oauth2.Token) error {
return SaveAuthToFile(r, f.filename)
return SaveAuthToFile(r, path.Join(f.dir, f.filename))
}

func SaveAuthToFile(r oauth2.Token, f string) error {
Expand Down

0 comments on commit 69f5340

Please sign in to comment.