authmiddleware

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2021 License: MIT Imports: 6 Imported by: 0

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

func (a *AuthMiddleware) GetUser(c *gin.Context) (*domain.User, error)

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.

Jump to

Keyboard shortcuts

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