crypto

package
v0.45.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CookieKeyJWTPayload   = "jwtPayload"
	CookieKeyJWTSignature = "jwtSignature"
	CookieKeyRefreshToken = "jwtRefreshToken"
)

Variables

This section is empty.

Functions

func ComparePasswords

func ComparePasswords(hashedPwd string, plainPwd string) bool

func HashAndSalt

func HashAndSalt(pwd []byte) ([]byte, error)

func New

func New(security config.Security) (Crypto, JWT, error)

Types

type Crypto

type Crypto interface {
	Encrypt(spec *modelV1.SecretSpec) error
	Decrypt(spec *modelV1.SecretSpec) error
}

type JWT

type JWT interface {
	SignedAccessToken(login string) (string, error)
	SignedRefreshToken(login string) (string, error)
	// CreateAccessTokenCookie will create two different cookies that contain a piece of the token.
	// As a reminder, a JWT token has the following structure: header.payload.signature
	// The first cookie will contain the struct header.payload that can then be manipulated by Javascript
	// The second cookie will contain the signature, and it won't be accessible by Javascript.
	CreateAccessTokenCookie(accessToken string) (*http.Cookie, *http.Cookie)
	DeleteAccessTokenCookie() (*http.Cookie, *http.Cookie)
	CreateRefreshTokenCookie(refreshToken string) *http.Cookie
	DeleteRefreshTokenCookie() *http.Cookie
	ValidateRefreshToken(token string) (*JWTCustomClaims, error)
	Middleware(skipper middleware.Skipper) echo.MiddlewareFunc
}

type JWTCustomClaims

type JWTCustomClaims struct {
	jwt.RegisteredClaims
}

func ExtractJWTClaims

func ExtractJWTClaims(ctx echo.Context) *JWTCustomClaims

Jump to

Keyboard shortcuts

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