forked from tangled.org/core
Monorepo for Tangled — https://tangled.org

appview/oauth: explicitly set service-auth token expiry

Signed-off-by: oppiliappan <me@oppi.li>

oppi.li ffcab7fe bf02ed25

verified
Changed files
+13 -1
appview
oauth
repo
+11 -1
appview/oauth/oauth.go
···
s.service = service
}
}
+
+
// Specify the Duration in seconds for the expiry of this token
+
//
+
// The time of expiry is calculated as time.Now().Unix() + exp
func WithExp(exp int64) ServiceClientOpt {
return func(s *ServiceClientOpts) {
-
s.exp = exp
+
s.exp = time.Now().Unix() + exp
}
}
···
authorizedClient, err := o.AuthorizedClient(r)
if err != nil {
return nil, err
+
}
+
+
// force expiry to atleast 60 seconds in the future
+
sixty := time.Now().Unix() + 60
+
if opts.exp < sixty {
+
opts.exp = sixty
}
resp, err := authorizedClient.ServerGetServiceAuth(r.Context(), opts.Audience(), opts.exp, opts.lxm)
+2
appview/repo/repo.go
···
r,
oauth.WithService(f.Spindle),
oauth.WithLxm(lxm),
+
oauth.WithExp(60),
oauth.WithDev(rp.config.Core.Dev),
if err != nil {
···
r,
oauth.WithService(f.Spindle),
oauth.WithLxm(tangled.RepoListSecretsNSID),
+
oauth.WithExp(60),
oauth.WithDev(rp.config.Core.Dev),
); err != nil {
log.Println("failed to create spindle client", err)