Download this file
| 1 | package provider |
| 2 | |
| 3 | import ( |
| 4 | "encoding/base64" |
| 5 | "encoding/json" |
| 6 | "strings" |
| 7 | "time" |
| 8 | ) |
| 9 | |
| 10 | // Expiry is read in memory and never included in evidence or diagnostics. |
| 11 | func credentialsExpired(raw []byte, now time.Time) bool { |
| 12 | var v struct { |
| 13 | Claude struct { |
| 14 | ExpiresAt int64 `json:"expiresAt"` |
| 15 | } `json:"claudeAiOauth"` |
| 16 | Tokens struct { |
| 17 | Access string `json:"access_token"` |
| 18 | } `json:"tokens"` |
| 19 | } |
| 20 | if json.Unmarshal(raw, &v) != nil { |
| 21 | return false |
| 22 | } |
| 23 | if v.Claude.ExpiresAt > 0 && v.Claude.ExpiresAt <= now.UnixMilli() { |
| 24 | return true |
| 25 | } |
| 26 | parts := strings.Split(v.Tokens.Access, ".") |
| 27 | if len(parts) != 3 { |
| 28 | return false |
| 29 | } |
| 30 | data, err := base64.RawURLEncoding.DecodeString(parts[1]) |
| 31 | if err != nil { |
| 32 | return false |
| 33 | } |
| 34 | var claims struct { |
| 35 | Exp int64 `json:"exp"` |
| 36 | } |
| 37 | return json.Unmarshal(data, &claims) == nil && claims.Exp > 0 && claims.Exp <= now.Unix() |
| 38 | } |
| 39 | |