Documentation ¶
Index ¶
- func CreateUserStore(usersJsonPath string) *xsync.MapOf[string, string]
- func GetTokenFromRequest(r *http.Request) string
- type Authenticator
- type MemoryAuthenticator
- func (*MemoryAuthenticator) Close() error
- func (a *MemoryAuthenticator) GetUsers() *xsync.MapOf[string, string]
- func (a *MemoryAuthenticator) Login(username string, password string) (string, error)
- func (a *MemoryAuthenticator) Logout(token string) (bool, error)
- func (a *MemoryAuthenticator) Validate(w http.ResponseWriter, r *http.Request) string
- type RedisAuthenticator
- func (a *RedisAuthenticator) Close() error
- func (a *RedisAuthenticator) GetUsers() *xsync.MapOf[string, string]
- func (a *RedisAuthenticator) Login(username string, password string) (string, error)
- func (a *RedisAuthenticator) Logout(token string) (bool, error)
- func (a *RedisAuthenticator) Validate(w http.ResponseWriter, r *http.Request) string
- type ReplaceableAuthenticator
- func (a *ReplaceableAuthenticator) Close() error
- func (a *ReplaceableAuthenticator) GetUsers() *xsync.MapOf[string, string]
- func (a *ReplaceableAuthenticator) Login(username string, password string) (string, error)
- func (a *ReplaceableAuthenticator) Logout(token string) (bool, error)
- func (a *ReplaceableAuthenticator) Validate(w http.ResponseWriter, r *http.Request) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateUserStore ¶
func GetTokenFromRequest ¶
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 ¶
func (a *MemoryAuthenticator) Validate(w http.ResponseWriter, r *http.Request) string
Validate is called on an HTTP API request and checks whether or not the user is authenticated.
type RedisAuthenticator ¶
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 ¶
func (a *RedisAuthenticator) Validate(w http.ResponseWriter, r *http.Request) string
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 ¶
func (a *ReplaceableAuthenticator) Validate(w http.ResponseWriter, r *http.Request) string
Validate is called on an HTTP API request and checks whether or not the user is authenticated.