MCPcopy
hub / github.com/golang-jwt/jwt / parseClaimsString

Method parseClaimsString

map_claims.go:69–87  ·  view source on GitHub ↗

parseClaimsString tries to parse a key in the map claims type as a [ClaimsStrings] type, which can either be a string or an array of string.

(key string)

Source from the content-addressed store, hash-verified

67// parseClaimsString tries to parse a key in the map claims type as a
68// [ClaimsStrings] type, which can either be a string or an array of string.
69func (m MapClaims) parseClaimsString(key string) (ClaimStrings, error) {
70 var cs []string
71 switch v := m[key].(type) {
72 case string:
73 cs = append(cs, v)
74 case []string:
75 cs = v
76 case []any:
77 for _, a := range v {
78 vs, ok := a.(string)
79 if !ok {
80 return nil, newError(fmt.Sprintf("%s is invalid", key), ErrInvalidType)
81 }
82 cs = append(cs, vs)
83 }
84 }
85
86 return cs, nil
87}
88
89// parseString tries to parse a key in the map claims type as a [string] type.
90// If the key does not exist, an empty string is returned. If the key has the

Callers 1

GetAudienceMethod · 0.95

Calls 1

newErrorFunction · 0.85

Tested by

no test coverage detected