Documentation ¶
Index ¶
- func AddUserIDHeader(r *http.Request, username string)
- func Authorization(authorizer Authorizer) func(http.Handler) http.Handler
- func GetToken(r *http.Request) (string, error)
- func GetUserIDFromRequest(r *http.Request) (string, error)
- func NewSessionID() string
- func RemoveUserIDHeader(r *http.Request)
- func SetAuthCookie(w http.ResponseWriter, tokenString string, expires time.Time)
- type Authorizer
- type Claim
- type Endpoints
- type JWT
- type Keys
- type LoginRequest
- type Session
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddUserIDHeader ¶
AddUserIDHeader adds a header to the request that represents the user ID
func Authorization ¶
func Authorization(authorizer Authorizer) func(http.Handler) http.Handler
Authorization verifies a request has a valid token associated
func GetUserIDFromRequest ¶
GetUserIDFromRequest returns the user ID from the request
func NewSessionID ¶
func NewSessionID() string
NewSessionID is used to generate unique session IDs for user authentication
func RemoveUserIDHeader ¶
RemoveUserIDHeader removes the header that contains the user ID
func SetAuthCookie ¶
func SetAuthCookie(w http.ResponseWriter, tokenString string, expires time.Time)
SetAuthCookie add an auth cookie to the response writer
Types ¶
type Authorizer ¶
type Authorizer interface { GenerateSecurityString(username string) (string, time.Time, error) Invalidate(token string) error Validate(token string) (bool, string, error) Cleanup(cleanInterval time.Duration) }
Authorizer is used to validate the user request
type Claim ¶
type Claim struct { Username string `json:"username"` jwt.RegisteredClaims }
Claim uses the standard JWT Claim to create a custom claim
type Endpoints ¶
type Endpoints struct {
// contains filtered or unexported fields
}
Endpoints used to authorize an end user
func NewEndpoints ¶
func NewEndpoints(ctx context.Context, isPasswordCorrect checkPassword, token Authorizer) *Endpoints
NewEndpoints is used setup the autorization endpoints
type JWT ¶
type JWT struct {
// contains filtered or unexported fields
}
JWT is used to generate and verify JST tokens
func NewJWTHandler ¶
NewJWTHandler is used to setup a JWT authorizer
func (*JWT) GenerateSecurityString ¶
GenerateSecurityString generates a JWT token for the provided username
func (*JWT) Invalidate ¶
Invalidate blacklists a token so that it cannot be used anymore
type Keys ¶
Keys is the interface that needs to be implemented to retrieve the key needed to sign a token
type LoginRequest ¶
LoginRequest is used to request access to the API
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session is used manage generated authentication sessions
func NewSessionHandler ¶
NewSessionHandler creates a structure to handle session authentication
func (*Session) GenerateSecurityString ¶
GenerateSecurityString creates a session id for the provided username
func (*Session) Invalidate ¶
Invalidate removes a session ID from the list of accepted session IDs