oidc

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseJWTSegment

func ParseJWTSegment(segment []byte, v any) error

func RequireOlder

func RequireOlder(t1, t2 []byte) error

RequireOlder returns an error if t1 is not older than t2

func SameIdentity

func SameIdentity(t1, t2 []byte) error

Compares two JWTs and determines if they are for the same identity (subject)

func SplitCompact

func SplitCompact(src []byte) ([]byte, []byte, []byte, error)

SplitCompact splits a JWT and returns its three parts separately: protected headers, payload and signature. This is copied from github.com/lestrrat-go/jwx/v2/jws.SplitCompact We include it here so so that jwx is not a dependency of simpleJws

Types

type Jws

type Jws struct {
	Payload    string      `json:"payload"`    // Base64 encoded
	Signatures []Signature `json:"signatures"` // Base64 encoded
}

func (*Jws) AddSignature

func (j *Jws) AddSignature(token []byte, opts ...SigOpts) error

func (*Jws) GetToken

func (j *Jws) GetToken(i int) ([]byte, error)

func (*Jws) GetTokenByTyp

func (j *Jws) GetTokenByTyp(typ string) ([]byte, error)

type Jwt

type Jwt struct {
	// contains filtered or unexported fields
}

func NewJwt

func NewJwt(token []byte) (*Jwt, error)

func (*Jwt) GetClaims

func (i *Jwt) GetClaims() *OidcClaims

func (*Jwt) GetPayload

func (i *Jwt) GetPayload() string

func (*Jwt) GetRaw

func (i *Jwt) GetRaw() []byte

func (*Jwt) GetSignature

func (i *Jwt) GetSignature() *Signature

type OidcClaims

type OidcClaims struct {
	Issuer     string `json:"iss"`
	Subject    string `json:"sub"`
	Audience   string `json:"-"`
	Expiration int64  `json:"exp"`
	IssuedAt   int64  `json:"iat"`
	Email      string `json:"email,omitempty"`
	Nonce      string `json:"nonce,omitempty"`
	Username   string `json:"preferred_username,omitempty"`
	FirstName  string `json:"given_name,omitempty"`
	LastName   string `json:"family_name,omitempty"`
}

func (*OidcClaims) UnmarshalJSON

func (id *OidcClaims) UnmarshalJSON(data []byte) error

Implement UnmarshalJSON for custom handling during JSON unmarshalling

type ProtectedClaims

type ProtectedClaims struct {
	Alg   string `json:"alg"`
	Jkt   string `json:"jkt,omitempty"`
	KeyID string `json:"kid,omitempty"`
	Type  string `json:"typ,omitempty"`
	CIC   string `json:"cic,omitempty"`
}

type SigOptStruct

type SigOptStruct struct {
	PublicHeader map[string]any
}

type SigOpts

type SigOpts func(a *SigOptStruct)

func WithPublicHeader

func WithPublicHeader(publicHeader map[string]any) SigOpts

WithPublicHeader species that a public header be included in the signature. Public headers aren't Base64 encoded because they aren't signed. Example use: WithPublicHeader(map[string]any{"key1": "abc", "key2": "def"})

type Signature

type Signature struct {
	Protected string `json:"protected"` // Base64 encoded

	Public    map[string]interface{} `json:"header,omitempty"`
	Signature string                 `json:"signature"` // Base64 encoded
	// contains filtered or unexported fields
}

func (*Signature) GetProtectedClaims

func (s *Signature) GetProtectedClaims() *ProtectedClaims

func (*Signature) GetTyp

func (s *Signature) GetTyp() (string, error)

type Tokens

type Tokens struct {
	IDToken      []byte
	RefreshToken []byte
	AccessToken  []byte
}

Jump to

Keyboard shortcuts

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