From 4cc16e849f4ae3355b9bb2a8474d25996dae983e Mon Sep 17 00:00:00 2001 From: Shirong Lu <73147033+happysnaker@users.noreply.github.com> Date: Fri, 3 Jul 2026 17:29:10 +0800 Subject: [PATCH] feat: add SetType and SetContentType helpers for Token Adds Token.SetType(typ) and Token.SetContentType(cty) methods as convenience helpers for setting the 'typ' and 'cty' header parameters defined in RFC 7519 Sections 5.1 and 5.2. These methods improve discoverability for registered header parameters compared to directly mutating Token.Header. Closes #497 --- token.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/token.go b/token.go index d9f6c9d2..a6b5675d 100644 --- a/token.go +++ b/token.go @@ -100,3 +100,15 @@ func (t *Token) SigningString() (string, error) { func (*Token) EncodeSegment(seg []byte) string { return base64.RawURLEncoding.EncodeToString(seg) } + +// SetType sets the "typ" (Type) header parameter as defined in RFC 7519 Section 5.1. +// Common values include "JWT", "at+jwt", etc. +func (t *Token) SetType(typ string) { + t.Header["typ"] = typ +} + +// SetContentType sets the "cty" (Content Type) header parameter as defined in RFC 7519 Section 5.2. +// This is used to declare the media type of the content in nested JWTs. +func (t *Token) SetContentType(cty string) { + t.Header["cty"] = cty +}