crypto

package
v0.55.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CookieKeyJWTPayload       = "jwtPayload"
	CookieKeyJWTSignature     = "jwtSignature"
	CookieKeyRefreshToken     = "jwtRefreshToken"
	CookieKeyOIDCToken        = "oidcToken"
	CookieKeyOIDCRefreshToken = "oidcRefreshToken"
)

Variables

This section is empty.

Functions

func ComparePasswords

func ComparePasswords(hashedPwd string, plainPwd string) bool

func HashAndSalt

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

func IsValidBcryptHash added in v0.55.0

func IsValidBcryptHash(hash string) bool

IsValidBcryptHash reports whether hash looks like a valid bcrypt hash. It does NOT verify the hash against any password — it only checks the format (prefix, cost, length).

func New

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

Types

type Crypto

type Crypto interface {
	Encrypt(spec *modelV1.SecretSpec) error
	// Decrypt decrypts the spec fields in place.
	// Returns true if the data was encrypted with the old format and needs re-encryption.
	Decrypt(spec *modelV1.SecretSpec) (bool, error)
}

type JWT

type JWT interface {
	SignedAccessToken(login string, providerInfo ProviderInfo, persistedClaims map[string][]string) (string, error)
	SignedRefreshToken(login string, providerInfo ProviderInfo, persistedClaims map[string][]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
	// OIDC Token Cookie stores the token from external IDP, to help implement a grafana feature OAuthPassThrough.
	// this token will be passed to datasources/globalDatasources when httpProxy.config.OauthPassthrough set to true.
	CreateOIDCTokenCookie(token *oauth2.Token) *http.Cookie
	DeleteOIDCTokenCookie() *http.Cookie
	CreateOIDCRefreshTokenCookie(refreshToken string) *http.Cookie
	DeleteOIDCRefreshTokenCookie() *http.Cookie
	ValidateRefreshToken(token string) (*JWTClaims, error)
	GetExpiresIn() int64
}

type JWTClaims added in v0.53.0

type JWTClaims struct {
	jwt.RegisteredClaims
	ProviderInfo
	// PersistedClaims holds selected upstream token claim values keyed by claim name.
	// Values are []string because OAuth/OIDC claims can be multi-valued (e.g. roles: ["admin","viewer"]).
	// Omitted for native-auth tokens.
	// +optional
	PersistedClaims map[string][]string `json:"prc,omitempty"`
}

type ProviderInfo added in v0.53.0

type ProviderInfo struct {
	ProviderKind string `json:"pkd"`
	ProviderID   string `json:"pid"`
}

type TokenRefresher added in v0.55.0

type TokenRefresher func(ctx echo.Context)

TokenRefresher is a function that attempts to refresh the upstream OIDC/OAuth token using the stored refresh token. It should set new cookies on success or clear them on failure.

Jump to

Keyboard shortcuts

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