auth

package
v0.0.0-...-1c2eb0b Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RefreshTokenCookieName = "RMX_REFRESH_TOKEN"
	RefreshTokenExpiry = time.Hour * 24 * 7
	AccessTokenExpiry  = time.Minute * 5
	EmailKey           = authCtxKey("rmx-email")
)

Variables

View Source
var (
	ErrNotImplemented = errors.New("not implemented")
	ErrGenerateKey    = errors.New("failed to generate new ecdsa key pair")
	ErrSignTokens     = errors.New("failed to generate signed tokens")
	ErrRTValidate     = errors.New("failed to validate refresh token")
)
View Source
var DefaultClient = &Client{
	rtdb: redis.NewClient(&redis.Options{Addr: defaultAddr, Password: defaultPassword, DB: 0}),
	cidb: redis.NewClient(&redis.Options{Addr: defaultAddr, Password: defaultPassword, DB: 1}),
}

Functions

func ES256

func ES256() (public, private jwk.Key)

func ParseCookie

func ParseCookie(r *http.Request, key jwk.Key, cookieName string) (jwt.Token, error)

func ParseRefreshTokenClaims

func ParseRefreshTokenClaims(token string) (jwt.Token, error)

func ParseRefreshTokenWithValidate

func ParseRefreshTokenWithValidate(key *jwk.Key, token string) (jwt.Token, error)

func ParseRequest

func ParseRequest(r *http.Request, key jwk.Key) (jwt.Token, error)

ParseRequest searches a http.Request object for a JWT token.

Specifying WithHeaderKey() will tell it to search under a specific header key. Specifying WithFormKey() will tell it to search under a specific form field.

By default, "Authorization" header will be searched.

If WithHeaderKey() is used, you must explicitly re-enable searching for "Authorization" header.

# searches for "Authorization"
jwt.ParseRequest(req)

# searches for "x-my-token" ONLY.
jwt.ParseRequest(req, jwt.WithHeaderKey("x-my-token"))

# searches for "Authorization" AND "x-my-token"
jwt.ParseRequest(req, jwt.WithHeaderKey("Authorization"), jwt.WithHeaderKey("x-my-token"))

func RS256

func RS256() (public, private jwk.Key)

func Sign

func Sign(key jwk.Key, o *TokenOption) ([]byte, error)

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewRedis

func NewRedis(addr, password string) *Client

func (*Client) BlackListClientID

func (c *Client) BlackListClientID(ctx context.Context, cid, email string) error

func (*Client) BlackListRefreshToken

func (c *Client) BlackListRefreshToken(ctx context.Context, token string) error

func (*Client) ValidateClientID

func (c *Client) ValidateClientID(ctx context.Context, cid string) error

func (*Client) ValidateRefreshToken

func (c *Client) ValidateRefreshToken(ctx context.Context, token string) error

type TokenOption

type TokenOption struct {
	IssuedAt   time.Time
	Issuer     string
	Audience   []string
	Subject    string
	Expiration time.Duration
	Claims     map[string]any
}

Jump to

Keyboard shortcuts

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