jwtinfo

package
v0.0.0-...-88bec2d Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseKVValue

func ParseKVValue(
	kv string,
	reqValuesMap map[string]string,
) (
	map[string]string,
	error,
)

ParseKVValue parses a string in the format "key=value" and adds it to the provided map. It returns an error if the format is invalid or the string is empty.

func ParseRequestJSONValues

func ParseRequestJSONValues(
	reqValues string,
	reqValuesMap map[string]string,
) (
	map[string]string,
	error,
)

ParseRequestJSONValues parses a JSON-encoded string of request values and merges them into the provided map.

func PrintTokenInfo

func PrintTokenInfo(jtd *JwtTokenData, w io.Writer) error

PrintTokenInfo prints the decoded JWT token information (headers and claims) to the provided writer in a human-readable format.

func ReadRequestValuesFile

func ReadRequestValuesFile(
	fileName string,
	reqValuesMap map[string]string,
) (
	map[string]string,
	error,
)

ReadRequestValuesFile reads request values from a JSON file and merges them into the provided map.

Types

type AllReader

type AllReader func(io.Reader) ([]byte, error)

AllReader is a function type that reads all data from an io.Reader.

type JwtTokenData

type JwtTokenData struct {
	// AccessTokenRaw is the raw base64-encoded access token string.
	AccessTokenRaw string `json:"access_token"` //nolint:tagliatelle // OAuth token field name
	// AccessTokenJwt is the parsed access token object.
	AccessTokenJwt *jwt.Token
	// AccessTokenHeader is the decoded JSON header of the access token.
	AccessTokenHeader []byte
	// AccessTokenClaims is the decoded JSON claims of the access token.
	AccessTokenClaims []byte
	// RefreshTokenRaw is the raw base64-encoded refresh token string.
	RefreshTokenRaw string `json:"refresh_token"` //nolint:tagliatelle // OAuth token field name
	// RefreshTokenJwt is the parsed refresh token object.
	RefreshTokenJwt *jwt.Token
	// RefreshTokenHeader is the decoded JSON header of the refresh token.
	RefreshTokenHeader []byte
	// RefreshTokenClaims is the decoded JSON claims of the refresh token.
	RefreshTokenClaims []byte
}

JwtTokenData holds the raw and parsed data for access and refresh tokens.

func ReadTokenFromFile

func ReadTokenFromFile(fileName string) (*JwtTokenData, error)

ReadTokenFromFile reads a JWT token string from the specified file. It returns a JwtTokenData struct containing the raw token string.

func RequestToken

func RequestToken(ctx context.Context, reqURL string, reqValues map[string]string, client *http.Client, readAll AllReader) (*JwtTokenData, error)

RequestToken makes an HTTP POST request to the given URL with the provided values to retrieve a JWT token. It handles both application/jwt and application/json response types.

func (*JwtTokenData) DecodeBase64

func (jtd *JwtTokenData) DecodeBase64() error

DecodeBase64 decodes the base64-encoded header and claims of the access and refresh tokens stored in the JwtTokenData struct.

func (*JwtTokenData) GetExpiration

func (jtd *JwtTokenData) GetExpiration() (time.Time, error)

GetExpiration extracts the expiration time (exp) from the token claims.

func (*JwtTokenData) GetIssuedAt

func (jtd *JwtTokenData) GetIssuedAt() (time.Time, error)

GetIssuedAt extracts the issued at time (iat) from the token claims.

func (*JwtTokenData) ParseUnverified

func (jtd *JwtTokenData) ParseUnverified() error

ParseUnverified parses the access token without verifying its signature.

func (*JwtTokenData) ParseWithJWKS

func (jtd *JwtTokenData) ParseWithJWKS(ctx context.Context, jwksURL string, keyfuncOverride keyfunc.Override) error

ParseWithJWKS parses and verifies the access token against the JSON Web Key Set (JWKS) provided at the given URL.

func (*JwtTokenData) Refresh

func (jtd *JwtTokenData) Refresh(
	ctx context.Context,
	reqURL string,
	reqValues map[string]string,
	client *http.Client,
	readAll AllReader,
) error

Refresh attempts to acquire a new token either by using the refresh token or the original request values.

func (*JwtTokenData) RefreshLoop

func (jtd *JwtTokenData) RefreshLoop(
	ctx context.Context,
	reqURL string,
	reqValues map[string]string,
	client *http.Client,
	readAll AllReader,
	renewThreshold float64,
	outFileName string,
	outWriter io.Writer,
) error

RefreshLoop runs a loop that periodically refreshes the JWT token before it expires.

func (*JwtTokenData) WriteTokenToFile

func (jtd *JwtTokenData) WriteTokenToFile(outFileName string, outWriter io.Writer)

WriteTokenToFile handles the persistence or display of a newly acquired token, either writing it to a file or printing it to the console.

Jump to

Keyboard shortcuts

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