authentication

package
v0.5.0-alpha.10 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2023 License: Apache-2.0 Imports: 16 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 AddBasicAuth

func AddBasicAuth(webAPI WebAPI, userManager *users.UserManager)

func AddIPWhiteListAuth

func AddIPWhiteListAuth(webAPI WebAPI, config IPWhiteListAuthConfiguration)

func AddNoneAuth

func AddNoneAuth(webAPI WebAPI)

func AddV1Authentication

func AddV1Authentication(
	webAPI WebAPI,
	userManager *users.UserManager,
	nodeIdentityProvider registry.NodeIdentityProvider,
	authConfig AuthConfiguration,
	claimValidator ClaimValidator,
)

func AddV2Authentication

func AddV2Authentication(apiRoot echoswagger.ApiRoot,
	userManager *users.UserManager,
	nodeIdentityProvider registry.NodeIdentityProvider,
	authConfig AuthConfiguration,
	claimValidator ClaimValidator,
) func() echo.MiddlewareFunc

func ValidatePermissions added in v1.0.3

func ValidatePermissions(permissions []string) func(next echo.HandlerFunc) echo.HandlerFunc

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) Name added in v1.0.3

func (a *AuthContext) Name() string

func (*AuthContext) Scheme

func (a *AuthContext) Scheme() string

type AuthHandler

type AuthHandler struct {
	Jwt         *JWTAuth
	UserManager *users.UserManager
}

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:"0.0.0.0" 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(config JWTAuthConfiguration, privateKey []byte, userManager *users.UserManager, claimValidator ClaimValidator) (*JWTAuth, func() echo.MiddlewareFunc)

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 ValidationError added in v1.0.3

type ValidationError struct {
	MissingPermission string `json:"missingPermission" swagger:"required"`
	Error             string `json:"error" swagger:"required"`
}

type WaspClaims

type WaspClaims struct {
	jwt.StandardClaims
	Permissions map[string]struct{} `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