Remind before LinkedIn's sign-in expires, and stop posting once it has

LinkedIn tokens last 60 days and can't be renewed without signing in
again. The expiry LinkedIn reports is now recorded (60 days from sign-in
for older connections). The LinkedIn card says until when; from two
weeks before, the Overview, the Inbox and the card remind you, with a
Reconnect button. Once expired, LinkedIn counts as not connected, due
posts come back to the Inbox saying why, and a 401 from LinkedIn reads
"reconnect LinkedIn" instead of the raw error.

Also fixes a leftover "Settings → Credentials" in a publish error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-21 11:43:59 -07:00
co-authored by Claude Opus 5.5
parent a2c8889599
commit 9c62680927
14 changed files with 159 additions and 9 deletions
+55 -1
View File
@@ -25,6 +25,57 @@ import (
type Connection struct {
Account string `json:"account"`
At time.Time `json:"at"`
// Expires is when the sign-in stops working, for networks whose tokens
// can't be renewed (LinkedIn); zero for ones Supermarket renews itself.
Expires time.Time `json:"expires,omitempty"`
}
// linkedInTokenLife is how long LinkedIn's access tokens last, for
// sign-ins saved before the expiry was recorded.
const linkedInTokenLife = 60 * 24 * time.Hour
// expiryWarning is how long before a sign-in expires the reminders start.
const expiryWarning = 14 * 24 * time.Hour
// Expiry is when a sign-in runs out, if it does.
type Expiry struct {
Network string // e.g. LinkedIn
At time.Time
}
// Expired reports whether it has run out.
func (e Expiry) Expired() bool { return !time.Now().Before(e.At) }
// Soon reports whether it runs out within expiryWarning (or has).
func (e Expiry) Soon() bool { return time.Until(e.At) < expiryWarning }
// Days is how many whole days are left (0 on the last day).
func (e Expiry) Days() int { return int(time.Until(e.At) / (24 * time.Hour)) }
// linkedInExpiry is when the LinkedIn sign-in runs out, or nil if LinkedIn
// isn't connected.
func (s *Server) linkedInExpiry() *Expiry {
if !s.Secrets.Has(secrets.LinkedInAccessToken) {
return nil
}
c := s.connections()["linkedin"]
at := c.Expires
if at.IsZero() {
if c.At.IsZero() {
return nil // a token from the old app: when it was made is unknown
}
at = c.At.Add(linkedInTokenLife)
}
return &Expiry{Network: "LinkedIn", At: at}
}
// reminders are the sign-ins running out soon, or already, for the
// Overview and the Inbox.
func (s *Server) reminders() []Expiry {
if e := s.linkedInExpiry(); e != nil && e.Soon() {
return []Expiry{*e}
}
return nil
}
const connectionsKey = "connections"
@@ -107,6 +158,7 @@ func (s *Server) dashboard(w http.ResponseWriter, r *http.Request) {
"ImportErr": errString(s.ImportErr),
"QueuedPosts": queued,
"Scheduled": len(scheduled),
"Reminders": s.reminders(),
"Pending": pending,
}})
}
@@ -153,7 +205,9 @@ func (s *Server) connectionSummary(c map[string]Connection) string {
} else if s.Secrets.Has(secrets.XAccessToken) {
parts = append(parts, "X")
}
if s.Secrets.Has(secrets.LinkedInAccessToken) {
if e := s.linkedInExpiry(); e != nil && e.Expired() {
parts = append(parts, "LinkedIn (expired)")
} else if s.Secrets.Has(secrets.LinkedInAccessToken) {
parts = append(parts, "LinkedIn")
}
if a := c["reddit"].Account; a != "" {