MCPcopy
hub / github.com/grpc/grpc-go / readToken

Method readToken

credentials/jwt/file_reader.go:49–66  ·  view source on GitHub ↗

readToken reads and parses a JWT token from the configured file. Returns the token string, expiration time, and any error encountered.

()

Source from the content-addressed store, hash-verified

47// readToken reads and parses a JWT token from the configured file.
48// Returns the token string, expiration time, and any error encountered.
49func (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
68const tokenDelim = "."
69

Calls 2

extractExpirationMethod · 0.95
ErrorfMethod · 0.65