dpop

package
v0.18.381 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: Apache-2.0 Imports: 20 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// HTTPHeader header name for DPoP
	HTTPHeader = "DPoP"
	// ContentType value
	ContentType = "application/dpop+jwt"
)
View Source
const (
	// DefaultExpiration for the proof
	DefaultExpiration = time.Minute * 10
	// DefaultNotBefore offset for NotBefore
	DefaultNotBefore = -10 * time.Minute
)
View Source
const (
	// CnfThumbprint is the claim name for JKT thumbptint
	CnfThumbprint = "jkt"
)

https://datatracker.ietf.org/doc/html/draft-ietf-oauth-dpop-04

Variables

View Source
var TimeNowFn = time.Now

TimeNowFn to override in unit tests

Functions

func ForRequest added in v0.6.0

func ForRequest(p Signer, r *http.Request, extraClaims interface{}) (string, error)

func GenerateKey added in v0.2.0

func GenerateKey(label string) (*jose.JSONWebKey, error)

GenerateKey returns JSONWebKey to sign JWT

func GetCnfClaim added in v0.2.0

func GetCnfClaim(claims map[string]interface{}) (string, error)

GetCnfClaim gets DPoP `cnf` claim

func LoadKey added in v0.2.0

func LoadKey(path string) (*jose.JSONWebKey, string, error)

LoadKey returns *jose.JSONWebKey

func SaveKey added in v0.2.0

func SaveKey(folder string, k *jose.JSONWebKey) (string, error)

SaveKey saves the key to storage

func SetCnfClaim added in v0.2.0

func SetCnfClaim(claims map[string]interface{}, thumprint string)

SetCnfClaim sets DPoP `cnf` claim

func Thumbprint added in v0.2.0

func Thumbprint(k *jose.JSONWebKey) (string, error)

Thumbprint returns key thumbprint

Types

type Result

type Result struct {
	Claims     *jwtgo.Claims
	Key        *jose.JSONWebKey
	Thumbprint string
}

Result is returned from VerifyClaims

func VerifyClaims

func VerifyClaims(cfg VerifyConfig, phdr, httpMethod, httpURI string) (*Result, error)

VerifyClaims returns DPoP claims, raw claims, key; or error

func VerifyRequestClaims added in v0.6.0

func VerifyRequestClaims(cfg VerifyConfig, req *http.Request) (*Result, error)

VerifyRequestClaims returns DPoP claims, raw claims, key; or error

type Signer

type Signer interface {
	// Sign returns DPoP token
	Sign(ctx context.Context, method string, u *url.URL, extraClaims interface{}) (string, error)
	// JWKThumbprint returns base64 hash of the key
	JWKThumbprint() string
}

Signer specifies an interface to sign HTTP requests with DPoP

func NewSigner

func NewSigner(s crypto.Signer) (Signer, error)

NewSigner creates a DPoP signer that can generate DPoP headers for a request.

type TokenInfo added in v0.2.0

type TokenInfo struct {
	Token       *jwt.JSONWebToken
	Claims      jwtgo.Claims
	Key         *jose.JSONWebKey
	Thumbprint  string
	CnfJkt      string
	IsPublicKey bool
	IsFresh     bool
}

TokenInfo is returned from GetTokenInfo

func GetTokenInfo added in v0.2.0

func GetTokenInfo(t string) *TokenInfo

GetTokenInfo returns token info, if it's JWT or nil otherwise

type VerifyConfig

type VerifyConfig struct {
	// ExpectedIssuer validates the iss claim of a JWT matches this value
	ExpectedIssuer string
	// ExpectedSubject validates the sub claim of a JWT matches this value
	ExpectedSubject string
	// ExpectedAudience validates that the aud claim of a JWT contains this value
	ExpectedAudience string
	// ExpectedNonce validates that the nonce claim of a JWT contains this value
	ExpectedNonce string
	// EnableQuery speciies to get `dpop` header from the QueryString
	EnableQuery bool
}

VerifyConfig expreses the possible options for validating a JWT

Jump to

Keyboard shortcuts

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