Documentation ¶
Index ¶
- Variables
- func NewHandlerAndAuthenticator(method SigningMethod, storage Storage, lifetime time.Duration, ...) (*Handler, *Authenticator)
- func NewUserContext(ctx context.Context, user *User) context.Context
- type Authenticator
- func (a *Authenticator) Authenticate(user string, pass string) (string, string, error)
- func (a *Authenticator) Generate(user *User) (string, error)
- func (a *Authenticator) GenerateRefresh(user *User) (string, error)
- func (a *Authenticator) ValidateRefresh(token string) (*User, error)
- func (a *Authenticator) ValidateToken(token string) (*User, error)
- type ECDSAKeyGen
- type Handler
- type RSAKeyGen
- type Request
- type Response
- type SigningMethod
- type Size
- type Storage
- type TokenGenerator
- type User
Constants ¶
This section is empty.
Variables ¶
var (
ErrTokenInvalid = errors.New("Token is invalid")
)
Errors returned from TokenGenerator
Functions ¶
func NewHandlerAndAuthenticator ¶
func NewHandlerAndAuthenticator(method SigningMethod, storage Storage, lifetime time.Duration, refreshLifetime time.Duration) (*Handler, *Authenticator)
NewHandlerAndAuthenticator creates a new login handler and Authenticator
Types ¶
type Authenticator ¶
type Authenticator struct {
// contains filtered or unexported fields
}
Authenticator is user authenticator and token generator
func NewAuthenticator ¶
func NewAuthenticator(generator *TokenGenerator, storage Storage, lifetime time.Duration, refreshLifetime time.Duration) *Authenticator
NewAuthenticator creates a Authenticator
func (*Authenticator) Authenticate ¶
Authenticate user and generate token
func (*Authenticator) Generate ¶
func (a *Authenticator) Generate(user *User) (string, error)
Generate token for UID
func (*Authenticator) GenerateRefresh ¶
func (a *Authenticator) GenerateRefresh(user *User) (string, error)
GenerateRefresh generates a refresh token for UID
func (*Authenticator) ValidateRefresh ¶
func (a *Authenticator) ValidateRefresh(token string) (*User, error)
ValidateRefresh refresh token and return UID
func (*Authenticator) ValidateToken ¶
func (a *Authenticator) ValidateToken(token string) (*User, error)
ValidateToken token and return UID
type ECDSAKeyGen ¶
type ECDSAKeyGen interface { KID() interface{} Key(kid interface{}) *ecdsa.PrivateKey }
ECDSAKeyGen gets ecdsa keys based on an id
func SimpleECDSAKeyGen ¶
func SimpleECDSAKeyGen(key *ecdsa.PrivateKey) ECDSAKeyGen
SimpleECDSAKeyGen ignores the kid and returnes a consitent private key
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is a login handler
func NewHandler ¶
func NewHandler(auth *Authenticator) *Handler
NewHandler creates a new login handler
func (*Handler) CtxServeHTTP ¶
CtxServeHTTP implements scaffold.Handler
type RSAKeyGen ¶
type RSAKeyGen interface { KID() interface{} Key(kid interface{}) *rsa.PrivateKey }
RSAKeyGen gets rsa keys based on an id
func SimpleRSAKeyGen ¶
func SimpleRSAKeyGen(key *rsa.PrivateKey) RSAKeyGen
SimpleRSAKeyGen ignores the kid and returnes a consitent private key
type Request ¶
type Request struct { Token string `json:"token"` Refresh string `json:"refresh_token"` Username string `json:"username"` Password string `json:"password"` }
Request is a request
func ParseRequest ¶
ParseRequest parses a request from a http.Request
func (*Request) UnmarshalJSON ¶
func (*Request) UnmarshalJSONFFLexer ¶
type Response ¶
type Response struct { Error string `json:"error,omitempty"` Token string `json:"token,omitempty"` RefreshToken string `json:"refresh_token,omitempty"` }
Response is a login response
func (*Response) MarshalJSON ¶
func (*Response) MarshalJSONBuf ¶
func (mj *Response) MarshalJSONBuf(buf fflib.EncodingBuffer) error
type SigningMethod ¶
type SigningMethod interface { KID() interface{} PublicKey(interface{}) interface{} PrivateKey(interface{}) interface{} Method() jwt.SigningMethod }
SigningMethod generates public and private keys
func SigningMethodECDSA ¶
func SigningMethodECDSA(keygen ECDSAKeyGen, size Size) SigningMethod
SigningMethodECDSA implements SigningMethod based off a private key
func SigningMethodHMAC ¶
func SigningMethodHMAC(secret []byte, size Size) SigningMethod
SigningMethodHMAC implements SigningMethod based off a secret
func SigningMethodRSA ¶
func SigningMethodRSA(keygen RSAKeyGen, size Size) SigningMethod
SigningMethodRSA implements SigningMethod based off a private key
func SigningMethodRSAPSS ¶
func SigningMethodRSAPSS(keygen RSAKeyGen, size Size) SigningMethod
SigningMethodRSAPSS implements SigningMethod based off a private key
type TokenGenerator ¶
type TokenGenerator struct {
// contains filtered or unexported fields
}
TokenGenerator generates and verifies tokens
func NewTokenGenerator ¶
func NewTokenGenerator(method SigningMethod) *TokenGenerator
NewTokenGenerator creates a new token generator
func (*TokenGenerator) Create ¶
func (t *TokenGenerator) Create() *jwt.Token
Create creates a new token using the correct method
func (*TokenGenerator) Sign ¶
func (t *TokenGenerator) Sign(token *jwt.Token) (string, error)
Sign signs the token and returns its string
func (*TokenGenerator) Verify ¶
func (t *TokenGenerator) Verify(str string) (*jwt.Token, error)
Verify verifies and parses a token string