authentication

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2022 License: Apache-2.0, BSD-2-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuthJWT         = "jwt"
	AuthBasic       = "basic"
	AuthIPWhitelist = "ip"
	AuthNone        = "none"
)

Variables

View Source
var (
	ErrJWTInvalidClaims = echo.NewHTTPError(http.StatusUnauthorized, "invalid jwt claims")
	ErrInvalidJWT       = echo.NewHTTPError(http.StatusUnauthorized, "token is invalid")
)

Errors

Functions

func AddAuthentication

func AddAuthentication(webAPI WebAPI, registryProvider registry.Provider, authConfig AuthConfiguration, claimValidator ClaimValidator)

func AddBasicAuth

func AddBasicAuth(webAPI WebAPI, userMap map[string]*users.UserData)

func AddIPWhiteListAuth

func AddIPWhiteListAuth(webAPI WebAPI, config IPWhiteListAuthConfiguration)

func AddNoneAuth

func AddNoneAuth(webAPI WebAPI)

Types

type AccessValidator

type AccessValidator func(validator ClaimValidator) bool

type AuthConfiguration

type AuthConfiguration struct {
	Scheme string `default:"ip" usage:"selects which authentication to choose"`

	JWTConfig         JWTAuthConfiguration         `name:"jwt" usage:"defines the jwt configuration"`
	BasicAuthConfig   BasicAuthConfiguration       `name:"basic" usage:"defines the basic auth configuration"`
	IPWhitelistConfig IPWhiteListAuthConfiguration `name:"ip" usage:"defines the whitelist configuration"`
}

type AuthContext

type AuthContext struct {
	echo.Context
	// contains filtered or unexported fields
}

func (*AuthContext) IsAllowedTo

func (a *AuthContext) IsAllowedTo(validator ClaimValidator) bool

func (*AuthContext) IsAuthenticated

func (a *AuthContext) IsAuthenticated() bool

func (*AuthContext) Scheme

func (a *AuthContext) Scheme() string

type AuthHandler

type AuthHandler struct {
	Jwt   *JWTAuth
	Users map[string]*users.UserData
}

func (*AuthHandler) CrossAPIAuthHandler

func (a *AuthHandler) CrossAPIAuthHandler(c echo.Context) error

type BasicAuthConfiguration

type BasicAuthConfiguration struct {
	Username string `default:"wasp" usage:"the username which grants access to the service"`
}

type ClaimValidator

type ClaimValidator func(claims *WaspClaims) bool

type IPWhiteListAuthConfiguration

type IPWhiteListAuthConfiguration struct {
	Whitelist []string `default:"127.0.0.1" usage:"a list of ips that are allowed to access the service"`
}

type JWTAuth

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

func AddJWTAuth

func AddJWTAuth(webAPI WebAPI, config JWTAuthConfiguration, privateKey []byte, userMap map[string]*users.UserData, claimValidator ClaimValidator) *JWTAuth

func NewJWTAuth

func NewJWTAuth(duration time.Duration, nodeID string, secret []byte) (*JWTAuth, error)

func (*JWTAuth) IssueJWT

func (j *JWTAuth) IssueJWT(username string, authClaims *WaspClaims) (string, error)

func (*JWTAuth) Middleware

func (j *JWTAuth) Middleware(skipper middleware.Skipper, allow MiddlewareValidator) echo.MiddlewareFunc

func (*JWTAuth) VerifyJWT

func (j *JWTAuth) VerifyJWT(token string, allow ClaimValidator) bool

type JWTAuthConfiguration

type JWTAuthConfiguration struct {
	Duration time.Duration `default:"24h" usage:"jwt token lifetime"`
}

type MiddlewareValidator

type MiddlewareValidator = func(c echo.Context, authContext *AuthContext) bool

type StatusWebAPIModel

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

type WaspClaims

type WaspClaims struct {
	jwt.StandardClaims
	Permissions map[string]bool `json:"permissions"`
}

func (*WaspClaims) HasPermission

func (c *WaspClaims) HasPermission(permission string) bool

func (*WaspClaims) VerifySubject

func (c *WaspClaims) VerifySubject(expected string) bool

type WebAPI

type WebAPI interface {
	GET(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	POST(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	Use(middleware ...echo.MiddlewareFunc)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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