authentication

package
v0.2.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JWTTokenKey = "kstone-api-jwt"

	SignMethodRS256 = "RS256"

	DataSuccess      = "success"
	DataUnauthorized = "failed to authenticate user"
	UserUnknown      = "unknown"

	DefaultKeyPath         = "/app/certs/private.key"
	DefaultKstoneNamespace = "kstone"
	DefaultUsername        = "admin"
	DefaultPassword        = "adm1n@kstone.io"
)

Variables

View Source
var (
	TokenProviders         = make(map[string]TokenFactory)
	AuthenticatorProviders = make(map[string]AuthenticatorFactory)
)
View Source
var DefaultConfigMapName = "kstone-api-user"

Functions

func CheckPassword

func CheckPassword(hashedPassword, password string) error

func GeneratePasswordHash

func GeneratePasswordHash(password string) (string, error)

func GetPrivateKey

func GetPrivateKey() (string, error)

func IsDefaultUser

func IsDefaultUser(username, password string) bool

func RegisterAuthenticatorFactory

func RegisterAuthenticatorFactory(name string, factory AuthenticatorFactory)

RegisterAuthenticatorFactory registers the specified authenticator provider

func RegisterTokenFactory

func RegisterTokenFactory(name string, factory TokenFactory)

RegisterTokenFactory registers the specified token provider

func SetAuthConfigMapName

func SetAuthConfigMapName(name string)

Types

type AuthenticatorContext

type AuthenticatorContext struct{}

type AuthenticatorFactory

type AuthenticatorFactory func(cfg *AuthenticatorContext) (Request, error)

type DefaultStore

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

func GetDefaultStoreInstance

func GetDefaultStoreInstance() *DefaultStore

func (*DefaultStore) UserAdd

func (s *DefaultStore) UserAdd(user User) error

func (*DefaultStore) UserChangePassword

func (s *DefaultStore) UserChangePassword(username, password string) error

func (*DefaultStore) UserDelete

func (s *DefaultStore) UserDelete(username string) error

func (*DefaultStore) UserGet

func (s *DefaultStore) UserGet(username string) (*User, error)

func (*DefaultStore) UserList

func (s *DefaultStore) UserList() ([]*User, error)

type Request

type Request interface {
	AuthenticateRequest(ctx *gin.Context) (*Response, bool, error)
}

Request attempts to extract authentication information from a request and returns a Response or an error if the request could not be checked.

func GetAuthenticatorProvider

func GetAuthenticatorProvider(name string, ctx *AuthenticatorContext) (Request, error)

GetAuthenticatorProvider gets the specified authenticator provider

type Response

type Response struct {
	Username      string `json:"username"`
	ResetPassword bool   `json:"reset_password"`
	Token         string `json:"token"`
	Message       string `json:"message"`
}

Response is the struct returned by authenticator interfaces

func InternalServerErrorResponse

func InternalServerErrorResponse(username string, message string) *Response

func SuccessResetPasswordResponse

func SuccessResetPasswordResponse(username string, token string) *Response

func SuccessResponse

func SuccessResponse(username string, message string) *Response

func SuccessTokenResponse

func SuccessTokenResponse(username string, token string) *Response

func UnauthenticatedResponse

func UnauthenticatedResponse() *Response

type Store

type Store interface {
	// UserGet gets a user
	UserGet(username string) (*User, error)
	// UserAdd adds a user
	UserAdd(user User) error
	// UserDelete deletes a user
	UserDelete(username string) error
	// UserList lists users
	UserList() ([]*User, error)
	// UserChangePassword changes a password of a user
	UserChangePassword(username, password string) error
}

Store gets and updates users

type Token

type Token interface {
	AuthenticateToken(ctx context.Context, token string) (*Response, bool, error)
}

Token checks a string value against a backing authentication store and returns a Response or an error if the token could not be checked.

func GetTokenProvider

func GetTokenProvider(name string, ctx *TokenContext) (Token, error)

GetTokenProvider gets the specified token provider

type TokenContext

type TokenContext struct {
	SignMethod string
	PrivateKey string
	TTL        string
}

type TokenFactory

type TokenFactory func(cfg *TokenContext) (Token, error)

type TokenGenerator

type TokenGenerator interface {
	GenerateToken(ctx context.Context, username string, password string) (string, error)
}

TokenGenerator generates tokens

type User

type User struct {
	Name           string
	HashedPassword string
	ExtraInfo      map[string]interface{}
}

Directories

Path Synopsis
token
jwt

Jump to

Keyboard shortcuts

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