Documentation
¶
Index ¶
- type RSAJWTService
- func (s *RSAJWTService) IssueInviteToken(ctx context.Context, inviteID string, expiry time.Duration) (string, error)
- func (s *RSAJWTService) IssueToken(ctx context.Context, agent *entities.Agent, accounts []*entities.Account, ...) (string, error)
- func (s *RSAJWTService) ReissueToken(ctx context.Context, claims *application.PericarpClaims, ...) (string, error)
- func (s *RSAJWTService) ValidateInviteToken(ctx context.Context, tokenString string) (*application.InviteClaims, error)
- func (s *RSAJWTService) ValidateToken(ctx context.Context, tokenString string) (*application.PericarpClaims, error)
- type RSAJWTServiceOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RSAJWTService ¶
type RSAJWTService struct {
// contains filtered or unexported fields
}
RSAJWTService implements application.JWTService using RS256 signing. It can be constructed without keys; calls to IssueToken/ValidateToken will return application.ErrNoSigningKey until a key is provided via options.
func NewRSAJWTService ¶
func NewRSAJWTService(opts ...RSAJWTServiceOption) *RSAJWTService
NewRSAJWTService creates a new RSAJWTService with the given options.
func (*RSAJWTService) IssueInviteToken ¶
func (s *RSAJWTService) IssueInviteToken(ctx context.Context, inviteID string, expiry time.Duration) (string, error)
IssueInviteToken creates a signed JWT for an invite.
func (*RSAJWTService) IssueToken ¶
func (s *RSAJWTService) IssueToken(ctx context.Context, agent *entities.Agent, accounts []*entities.Account, activeAccountID string, subscription *auth.SubscriptionClaim, extras map[string]any) (string, error)
IssueToken implements application.JWTService.IssueToken. See the interface doc for the extras / reserved-name contract.
func (*RSAJWTService) ReissueToken ¶
func (s *RSAJWTService) ReissueToken(ctx context.Context, claims *application.PericarpClaims, activeAccountID string) (string, error)
ReissueToken creates a new JWT with a different ActiveAccountID, copying AgentID, Subject, AccountIDs, Subscription, and Extras from the existing claims. Subscription and Extras are copied verbatim — account-switch reissuance prefers a stale-but-stable snapshot over a per-switch billing or enricher call. Fresh snapshots are only taken on the next IssueIdentityToken (e.g. when the JWT expires and the user re-authenticates).
Extras are re-validated even though the source token was already validated when first parsed: the reserved-name set may have grown since the token was issued, an alternate JWTService implementation may not have enforced ValidateExtras, or the claims pointer may have been mutated in memory between ValidateToken and ReissueToken.
func (*RSAJWTService) ValidateInviteToken ¶
func (s *RSAJWTService) ValidateInviteToken(ctx context.Context, tokenString string) (*application.InviteClaims, error)
ValidateInviteToken parses and validates an invite token string, returning the claims.
func (*RSAJWTService) ValidateToken ¶
func (s *RSAJWTService) ValidateToken(ctx context.Context, tokenString string) (*application.PericarpClaims, error)
ValidateToken parses and validates a JWT string, returning the claims.
type RSAJWTServiceOption ¶
type RSAJWTServiceOption func(*RSAJWTService)
RSAJWTServiceOption configures the RSAJWTService.
func WithIssuer ¶
func WithIssuer(issuer string) RSAJWTServiceOption
WithIssuer sets the JWT issuer claim. Default is "pericarp".
func WithSigningKey ¶
func WithSigningKey(key *rsa.PrivateKey) RSAJWTServiceOption
WithSigningKey sets the RSA private key for signing tokens. The corresponding public key is derived automatically for validation.
func WithTokenTTL ¶
func WithTokenTTL(ttl time.Duration) RSAJWTServiceOption
WithTokenTTL sets the token time-to-live. Default is 15 minutes.