jwt

package
v0.4.31 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const JWKSPath = ".well-known/jwks.json"

Variables

This section is empty.

Functions

func GenerateJwksJSON

func GenerateJwksJSON(publicKey *ecdsa.PublicKey) ([]byte, error)

func GenerateKeyPair

func GenerateKeyPair() (*ecdsa.PrivateKey, *ecdsa.PublicKey, error)

func GenerateToken

func GenerateToken(username string, privateKey *ecdsa.PrivateKey, id int, issuer string, t time.Duration) (string, error)

func GetAccessToken

func GetAccessToken(username string, privateKey *ecdsa.PrivateKey, id int) (string, error)

get AccessToken

func GetRefreshToken

func GetRefreshToken(username string, private *ecdsa.PrivateKey, id int) (string, error)

func JWKSHandler

func JWKSHandler(jwksJSON []byte) http.Handler

func PublicKeyFromJwksJSON

func PublicKeyFromJwksJSON(jwksJSON []byte) (*ecdsa.PublicKey, error)

func TokenFromAuthorization added in v0.4.31

func TokenFromAuthorization(authorization string) string

TokenFromAuthorization is the user token in an Authorization header value: the bare token (as CasaOS clients have always sent it), or the standard `Bearer <token>` (RFC 6750; the scheme is case-insensitive, RFC 7235). Every other scheme, `Internal <secret>` among them, is returned as it came: it parses as no token.

Types

type Claims

type Claims struct {
	Username string `json:"username"`
	ID       int    `json:"id"`
	jwt.RegisteredClaims
}

func ParseToken

func ParseToken(signedToken string, publicKeyFunc func() (*ecdsa.PublicKey, error)) (*Claims, error)

func Validate

func Validate(token string, publicKeyFunc func() (*ecdsa.PublicKey, error)) (bool, *Claims, error)

type JWK

type JWK struct {
	Kty string `json:"kty"`
	Crv string `json:"crv"`
	X   string `json:"x"`
	Y   string `json:"y"`
}

type JWKS

type JWKS struct {
	Keys []JWK `json:"keys"`
}

Jump to

Keyboard shortcuts

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