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)
| 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. |
| 69 | func (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 |