readToken reads and parses a JWT token from the configured file. Returns the token string, expiration time, and any error encountered.
()
| 47 | // readToken reads and parses a JWT token from the configured file. |
| 48 | // Returns the token string, expiration time, and any error encountered. |
| 49 | func (r *jwtFileReader) readToken() (string, time.Time, error) { |
| 50 | tokenBytes, err := os.ReadFile(r.tokenFilePath) |
| 51 | if err != nil { |
| 52 | return "", time.Time{}, fmt.Errorf("%v: %w", err, errTokenFileAccess) |
| 53 | } |
| 54 | |
| 55 | token := strings.TrimSpace(string(tokenBytes)) |
| 56 | if token == "" { |
| 57 | return "", time.Time{}, fmt.Errorf("token file %q is empty: %w", r.tokenFilePath, errJWTValidation) |
| 58 | } |
| 59 | |
| 60 | exp, err := r.extractExpiration(token) |
| 61 | if err != nil { |
| 62 | return "", time.Time{}, fmt.Errorf("token file %q: %v: %w", r.tokenFilePath, err, errJWTValidation) |
| 63 | } |
| 64 | |
| 65 | return token, exp, nil |
| 66 | } |
| 67 | |
| 68 | const tokenDelim = "." |
| 69 |