auth

package
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2022 License: MIT Imports: 14 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPasswordHash

func CheckPasswordHash(password, hash string) bool

CheckPasswordHash compares a password against its hash

func HashPassword

func HashPassword(password string) (string, error)

HashPassword creates a cryptograhic hash of a password

func LoadJwkSetFromFile

func LoadJwkSetFromFile(jwkSetFile string) (jwk.Set, error)

LoadJwkSetFromFile ...

func MustHashPassword

func MustHashPassword(pw string) string

MustHashPassword creates a cryptographic hash of a password or panics

func ParseJwkSet

func ParseJwkSet(jwkSetData []byte) (jwk.Set, error)

ParseJwkSet ...

func ParseSigningKeyFromPEMData

func ParseSigningKeyFromPEMData(keyData []byte) (*rsa.PrivateKey, error)

ParseSigningKeyFromPEMData parses a private RSA signing key from PEM data

func ParseSigningKeyFromPEMFile

func ParseSigningKeyFromPEMFile(path string) (*rsa.PrivateKey, error)

ParseSigningKeyFromPEMFile parses a private RSA signing key from a PEM file

func ToJwks

func ToJwks(pub *rsa.PublicKey) (jwk.Set, error)

ToJwks converts a RSA public key to a JWK set

func ToJwksJSON

func ToJwksJSON(pub *rsa.PublicKey) ([]byte, error)

ToJwksJSON converts a RSA public key to a JSON encoded JWK set

func ToPEM

func ToPEM(key *rsa.PrivateKey) []byte

ToPEM converts a RSA private key into PEM format

Types

type Authenticator

type Authenticator struct {
	Issuer       string
	Audience     string
	ExpiresAfter time.Duration

	SignKey *rsa.PrivateKey
	JwkSet  jwk.Set
}

Authenticator provides convenient methods for signing and validating JWT claims

func (*Authenticator) SetupKeys

func (auth *Authenticator) SetupKeys(config *KeyConfig) error

SetupKeys loads or generates keys from the config

func (*Authenticator) SignJwtClaims

func (auth *Authenticator) SignJwtClaims(claims Claims) (string, error)

SignJwtClaims signs JWT claims using RS256 and returns the token string

func (*Authenticator) Validate

func (auth *Authenticator) Validate(tokenString string, claims Claims) (bool, *jwt.Token, error)

Validate checks a token if it is valid (e.g. has not expired)

type Claims

type Claims interface {
	jwt.Claims
	GetRegisteredClaims() *jwt.RegisteredClaims
}

Claims defines the interface that custom JWT claim types must implement

type JWK

type JWK struct {
	KID       string `json:"kid"`
	Algorithm string `json:"alg"`
	E         string `json:"e"`
	KTY       string `json:"kty"`
	N         string `json:"n"`
}

JWK encodes a JSON web key

type KeyConfig added in v0.0.14

type KeyConfig struct {
	Jwks     string
	JwksFile string
	Key      string
	KeyFile  string
	Generate bool
}

KeyConfig configures the keys that will be used for authentication

type RSAKeyPair

type RSAKeyPair struct {
	PrivateKey *rsa.PrivateKey
	PublicKey  *rsa.PublicKey
}

RSAKeyPair is an RSA key pair

func GenerateRSAKeyPair

func GenerateRSAKeyPair() (*RSAKeyPair, error)

GenerateRSAKeyPair generates an RSA key pair

Jump to

Keyboard shortcuts

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