MCPcopy Create free account
hub / github.com/coder/coder / validateClaims

Function validateClaims

enterprise/coderd/license/license.go:695–723  ·  view source on GitHub ↗
(tok *jwt.Token)

Source from the content-addressed store, hash-verified

693}
694
695func validateClaims(tok *jwt.Token) (*Claims, error) {
696 if claims, ok := tok.Claims.(*Claims); ok {
697 if claims.Version != uint64(CurrentVersion) {
698 return nil, ErrInvalidVersion
699 }
700 if claims.IssuedAt == nil {
701 return nil, ErrMissingIssuedAt
702 }
703 if claims.NotBefore == nil {
704 return nil, ErrMissingNotBefore
705 }
706
707 yearsHardLimit := time.Now().Add(5 /* years */ * 365 * 24 * time.Hour)
708 if claims.LicenseExpires == nil || claims.LicenseExpires.Time.After(yearsHardLimit) {
709 return nil, ErrMissingLicenseExpires
710 }
711 if claims.ExpiresAt == nil {
712 return nil, ErrMissingExp
713 }
714 if claims.AccountType == "" {
715 return nil, ErrMissingAccountType
716 }
717 if claims.AccountID == "" {
718 return nil, ErrMissingAccountID
719 }
720 return claims, nil
721 }
722 return nil, xerrors.New("unable to parse Claims")
723}
724
725// ParseClaimsIgnoreNbf validates a raw JWT, but ignores `nbf` claim. If otherwise valid, it returns
726// the claims. If unparsable or invalid, it returns an error. Ignoring the `nbf` (not before) is

Callers 2

ParseClaimsFunction · 0.85
ParseClaimsIgnoreNbfFunction · 0.85

Calls 2

AddMethod · 0.65
NewMethod · 0.65

Tested by

no test coverage detected