Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthMiddleware ¶
type AuthMiddleware struct {
AuthService *domain.AuthService
ParseToken ParseTokenFunc
}
AuthMiddleware handles authentication by using AuthService to determine if a request is authenticated.
func New ¶
func New(authService *domain.AuthService, parseTokenFunc ParseTokenFunc) *AuthMiddleware
New returns a new AuthMiddleware configured with the specified AuthService and ParseTokenFunc.
func Provide ¶
func Provide(authService domain.AuthService, parseToken ParseTokenFunc) *AuthMiddleware
Provide returns an AuthMiddleware configured with the provided AuthService and ParsTokenFunc.
func (*AuthMiddleware) GetUser ¶
GetUser attempts to get a User object from the provided Context. This is performed by passing the found AuthToken within the request (if any) to an AuthService which performs the User lookup.
func (*AuthMiddleware) HandleAuth ¶
func (a *AuthMiddleware) HandleAuth() gin.HandlerFunc
HandleAuth checks a request for valid authentication using the token obtained from the ParseToken function against the AuthService.
type ParseTokenFunc ¶
type ParseTokenFunc = func(r *http.Request) (*domain.TokenValue, error)
ParseTokenFunc defines a function which parses an HTTP request for an authorization token.
func ProvideAuthorizationHeaderParser ¶
func ProvideAuthorizationHeaderParser() ParseTokenFunc
ProvideAuthorizationHeaderParser returns a ParseTokenFunc which parses the Authorization header for a Bearer token.