auth

package
v0.0.0-...-37a2a66 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateUserStore

func CreateUserStore(usersJsonPath string) *xsync.MapOf[string, string]

func GetTokenFromRequest

func GetTokenFromRequest(r *http.Request) string

GetTokenFromRequest gets the token from the request header or cookie.

Types

type Authenticator

type Authenticator interface {
	// GetUsers returns a Map with all the users and their corresponding passwords.
	GetUsers() *xsync.MapOf[string, string]
	// Validate is called on an HTTP API request and returns the user's name if request is authenticated.
	Validate(w http.ResponseWriter, r *http.Request) string
	// Login allows logging in a user and returning the token.
	Login(username string, password string) (string, error)
	// Logout allows logging out of a user and deleting the token from the server.
	Logout(token string) (bool, error)
	// Close closes the authenticator. Once closed, the authenticator should not be used.
	Close() error
}

Authenticator is used by Octyne's Connector to provide HTTP API authentication.

func NewMemoryAuthenticator

func NewMemoryAuthenticator(usersJsonPath string) Authenticator

NewMemoryAuthenticator initializes an authenticator using memory for token storage.

type MemoryAuthenticator

type MemoryAuthenticator struct {
	Users  *xsync.MapOf[string, string]
	Tokens *xsync.MapOf[string, string]
}

MemoryAuthenticator is an Authenticator implementation using an array to store tokens.

func (*MemoryAuthenticator) Close

func (*MemoryAuthenticator) Close() error

Close closes the authenticator. This is no-op for MemoryAuthenticator.

func (*MemoryAuthenticator) GetUsers

func (a *MemoryAuthenticator) GetUsers() *xsync.MapOf[string, string]

GetUsers returns a Map with all the users and their corresponding passwords.

func (*MemoryAuthenticator) Login

func (a *MemoryAuthenticator) Login(username string, password string) (string, error)

Login allows logging in a user and returning the token.

func (*MemoryAuthenticator) Logout

func (a *MemoryAuthenticator) Logout(token string) (bool, error)

Logout allows logging out of a user and deleting the token from the server.

func (*MemoryAuthenticator) Validate

Validate is called on an HTTP API request and checks whether or not the user is authenticated.

type RedisAuthenticator

type RedisAuthenticator struct {
	Users *xsync.MapOf[string, string]
	Redis *redis.Pool
	URL   string
}

RedisAuthenticator is an Authenticator implementation using Redis to store tokens.

func NewRedisAuthenticator

func NewRedisAuthenticator(usersJsonPath string, url string) *RedisAuthenticator

NewRedisAuthenticator initializes an authenticator using Redis for token storage.

func (*RedisAuthenticator) Close

func (a *RedisAuthenticator) Close() error

Close closes the authenticator. Once closed, the authenticator should not be used.

func (*RedisAuthenticator) GetUsers

func (a *RedisAuthenticator) GetUsers() *xsync.MapOf[string, string]

GetUsers returns a Map with all the users and their corresponding passwords.

func (*RedisAuthenticator) Login

func (a *RedisAuthenticator) Login(username string, password string) (string, error)

Login allows logging in a user and returning the token.

func (*RedisAuthenticator) Logout

func (a *RedisAuthenticator) Logout(token string) (bool, error)

Logout allows logging out of a user and deleting the token from the server.

func (*RedisAuthenticator) Validate

Validate is called on an HTTP API request and checks whether or not the user is authenticated.

type ReplaceableAuthenticator

type ReplaceableAuthenticator struct {
	Engine      Authenticator
	EngineMutex sync.RWMutex
}

ReplaceableAuthenticator is an Authenticator implementation that allows replacing the underlying Authenticator in a thread-safe manner on the fly.

func (*ReplaceableAuthenticator) Close

func (a *ReplaceableAuthenticator) Close() error

Close closes the authenticator. Once closed, the authenticator should not be used.

func (*ReplaceableAuthenticator) GetUsers

func (a *ReplaceableAuthenticator) GetUsers() *xsync.MapOf[string, string]

GetUsers returns a Map with all the users and their corresponding passwords.

func (*ReplaceableAuthenticator) Login

func (a *ReplaceableAuthenticator) Login(username string, password string) (string, error)

Login allows logging in a user and returning the token.

func (*ReplaceableAuthenticator) Logout

func (a *ReplaceableAuthenticator) Logout(token string) (bool, error)

Logout allows logging out of a user and deleting the token from the server.

func (*ReplaceableAuthenticator) Validate

Validate is called on an HTTP API request and checks whether or not the user is authenticated.

Jump to

Keyboard shortcuts

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