session

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 26, 2026 License: MIT Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package session contains types and functions for working with authentication sessions.

Index

Constants

View Source
const Leeway = time.Second * 5

Leeway is the amount of leeway permitted in a session's expiration time allowing for clock skew between the authenticator and the client.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClaimsDecoder

type ClaimsDecoder interface {
	Claims(v any) error
}

A ClaimsDecoder is an interface for decoding JWT claims into a target JSON-decodable object.

type MissingRequiredClaimError

type MissingRequiredClaimError struct {
	Claim string
}

MissingRequiredClaimError is returned when a required claim is not provided.

func (MissingRequiredClaimError) Error

type Session

type Session struct {
	Anonymous bool            `json:"-"`
	UID       string          `json:"u"`
	ExpiresAt int64           `json:"e,omitempty"`
	Claims    json.RawMessage `json:"c,omitempty"`
}

Session represents an authentication session. A session can be one that is authenticated (anonymous) or authenticated with a user identity. A session may optionally expire.

func Anonymous

func Anonymous() *Session

Anonymous returns a session to use when a request is unauthenticated.

func NewFromClaims

func NewFromClaims(uidClaim string, claims ClaimsDecoder) (*Session, error)

NewFromClaims creates a new session from JWT claims. It assumes that the provided claims have been already validated.

The provided uidClaim is used to extract the username from the token's claims. It must exist and be a string type in the token's claims.

func (*Session) Expires

func (s *Session) Expires() time.Time

Expires returns the expiration time of the session. Returns a zero time if the session has no expiration time.

func (*Session) ValidateClock

func (s *Session) ValidateClock(now time.Time) error

ValidateClock checks if the session is still valid. If the session has expired, then it returns an oidc.TokenExpiredError.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL