aboutsummaryrefslogtreecommitdiffstats
path: root/fikenauth/source.go
diff options
context:
space:
mode:
authorSimen A. W. Olsen <hello@simenandre.no>2026-11-03 22:08:49 +0100
committerSimen A. W. Olsen <hello@simenandre.no>2026-11-03 22:08:49 +0100
commitbef3ccf4521d4ed431f3cdfc66e618c619ce28e4 (patch)
treeef8e6ff90fed4b27d4f2cfd082106f2efdb38ca5 /fikenauth/source.go
parenta5491c9dccdf4678bf3b4380d208cf2562afeee4 (diff)
downloadfiken-bef3ccf4521d4ed431f3cdfc66e618c619ce28e4.tar.gz
fiken-bef3ccf4521d4ed431f3cdfc66e618c619ce28e4.zip
Share one Fiken login between programsHEADv0.4.0main
fikenconfig keeps an OAuth app and a grant per account in ~/.config/fiken, and finds the account that reaches a company. Renewing a grant takes a lock, so programs sharing it take turns.
Diffstat (limited to 'fikenauth/source.go')
-rw-r--r--fikenauth/source.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/fikenauth/source.go b/fikenauth/source.go
index f6289c2..0a61479 100644
--- a/fikenauth/source.go
+++ b/fikenauth/source.go
@@ -52,6 +52,23 @@ func (s *Source) Token(ctx context.Context) (string, error) {
if s.token.Valid(s.cfg.now()) {
return s.token.AccessToken, nil
}
+
+ // Another program sharing the file may be renewing it right now. Fiken
+ // rotates the refresh token on every renewal, so renewing twice from one
+ // refresh token logs out whichever finishes second. The lock orders them,
+ // and reading again under it picks up what the first one saved.
+ unlock, err := s.store.lock()
+ if err != nil {
+ return "", err
+ }
+ defer unlock()
+ if s.token, err = s.store.Load(); err != nil {
+ s.loaded = false
+ return "", err
+ }
+ if s.token.Valid(s.cfg.now()) {
+ return s.token.AccessToken, nil
+ }
if !s.token.Renewable() {
return "", fmt.Errorf("the Fiken access token has expired and cannot be renewed: %w", ErrNoToken)
}