Skip to content

Claims

Claims

go
type Claims struct {
    UserID      string         `json:"user_id,omitempty"`
    Username    string         `json:"username,omitempty"`
    Role        string         `json:"role,omitempty"`
    Permissions []string       `json:"permissions,omitempty"`
    Scopes      []string       `json:"scopes,omitempty"`
    Extra       map[string]any `json:"extra,omitempty"`
    SessionID   string         `json:"session_id,omitempty"`
    ClientID    string         `json:"client_id,omitempty"`
    RegisteredClaims
}

Built-in Claims structure containing common business fields and standard JWT fields.

struct

Fields

FieldTypeDescription
UserIDstringUser ID
UsernamestringUsername
RolestringRole
Permissions[]stringPermission list
Scopes[]stringScope list
Extramap[string]anyCustom extension fields
SessionIDstringSession ID
ClientIDstringClient ID
RegisteredClaimsRegisteredClaimsStandard JWT fields

Validation Rules

The Validate() method checks that at least one of UserID or Username is non-empty.

The Processor performs additional deep validation during token creation and validation (via the internal validateClaims function):

RuleLimit
String field lengthMax 256 characters
Array field sizeMax 100 items
Extra field countMax 50 keys
Extra value typesOnly string and []string allowed; nested maps and other types are rejected
Control charactersCharacters other than tab, newline, and carriage return are rejected
Injection pattern detectionRejected when containing HTML/SQL/path traversal patterns

Methods

MethodSignatureDescription
GetRegisteredClaimsfunc (c *Claims) GetRegisteredClaims() *RegisteredClaimsReturns the embedded standard fields
Validatefunc (c *Claims) Validate() errorChecks that at least one of UserID or Username is non-empty

RegisteredClaims

go
type RegisteredClaims struct {
    Issuer    string        `json:"iss,omitempty"`
    Subject   string        `json:"sub,omitempty"`
    Audience  StringOrSlice `json:"aud,omitempty"`
    ExpiresAt NumericDate   `json:"exp"`
    NotBefore NumericDate   `json:"nbf"`
    IssuedAt  NumericDate   `json:"iat"`
    ID        string        `json:"jti,omitempty"`
    TokenType string        `json:"token_type,omitempty"`
}

Standard JWT registered claims (RFC 7519).

struct

Fields

FieldTypeJSON TagDescription
IssuerstringissIssuer
SubjectstringsubSubject
AudienceStringOrSliceaudAudience
ExpiresAtNumericDateexpExpiration time
NotBeforeNumericDatenbfNot-before time
IssuedAtNumericDateiatIssued-at time
IDstringjtiToken ID
TokenTypestringtoken_typeToken type (access or refresh; see Token Type Constants)