ParseRaw consumes a license and returns the claims.
(l string, keys map[string]ed25519.PublicKey)
| 656 | |
| 657 | // ParseRaw consumes a license and returns the claims. |
| 658 | func ParseRaw(l string, keys map[string]ed25519.PublicKey) (jwt.MapClaims, error) { |
| 659 | tok, err := jwt.Parse( |
| 660 | l, |
| 661 | keyFunc(keys), |
| 662 | jwt.WithValidMethods(ValidMethods), |
| 663 | ) |
| 664 | if err != nil { |
| 665 | return nil, err |
| 666 | } |
| 667 | if claims, ok := tok.Claims.(jwt.MapClaims); ok && tok.Valid { |
| 668 | version, ok := claims[VersionClaim].(float64) |
| 669 | if !ok { |
| 670 | return nil, ErrInvalidVersion |
| 671 | } |
| 672 | if int64(version) != CurrentVersion { |
| 673 | return nil, ErrInvalidVersion |
| 674 | } |
| 675 | return claims, nil |
| 676 | } |
| 677 | return nil, xerrors.New("unable to parse Claims") |
| 678 | } |
| 679 | |
| 680 | // ParseClaims validates a raw JWT, and if valid, returns the claims. If |
| 681 | // unparsable or invalid, it returns an error |