auth

package
v2.3.4+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2018 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultRedisPrefix = "gateway:"

DefaultRedisPrefix is used as prefix when no prefix is given

View Source
var ErrGatewayNoValidToken = errors.New("Gateway does not have a valid access token")

ErrGatewayNoValidToken is returned when a gateway does not have a valid access token

View Source
var ErrGatewayNotFound = errors.New("Gateway not found")

ErrGatewayNotFound is returned when a gateway was not found

Functions

This section is empty.

Types

type AccountServerExchanger

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

AccountServerExchanger uses a TTN Account Server to exchange the key for a token

func (*AccountServerExchanger) Exchange

func (a *AccountServerExchanger) Exchange(gatewayID, key string) (token string, expires time.Time, err error)

Exchange implements the Exchanger interface

type Exchanger

type Exchanger interface {
	Exchange(gatewayID, key string) (token string, expires time.Time, err error)
}

Exchanger interface exchanges a gateway access key for a gateway token

func NewAccountServer

func NewAccountServer(accountServer string, ctx log.Interface) Exchanger

NewAccountServer returns a new AccountServerExchanger for the given TTN Account Server

type Interface

type Interface interface {
	SetToken(gatewayID string, token string, expires time.Time) error
	SetKey(gatewayID string, key string) error

	ValidateKey(gatewayID string, key string) error

	Delete(gatewayID string) error

	// GetToken returns the access token for a gateway; it exchanges the key for an access token if necessary
	GetToken(gatewayID string) (token string, err error)
	SetExchanger(Exchanger)
}

Interface for gateway authentication

func NewMemory

func NewMemory() Interface

NewMemory returns a new authentication interface with an in-memory backend

func NewRedis

func NewRedis(client *redis.Client, prefix string) Interface

NewRedis returns a new authentication interface with a redis backend

type Memory

type Memory struct {
	Exchanger
	// contains filtered or unexported fields
}

Memory implements the authentication interface with an in-memory backend

func (*Memory) Delete

func (m *Memory) Delete(gatewayID string) error

Delete gateway key and token

func (*Memory) GetToken

func (m *Memory) GetToken(gatewayID string) (string, error)

GetToken returns an access token for the gateway

func (*Memory) SetExchanger

func (m *Memory) SetExchanger(e Exchanger)

SetExchanger sets the component that will exchange access keys for access tokens

func (*Memory) SetKey

func (m *Memory) SetKey(gatewayID string, key string) error

SetKey sets the access key for a gateway

func (*Memory) SetToken

func (m *Memory) SetToken(gatewayID string, token string, expires time.Time) error

SetToken sets the access token for a gateway

func (*Memory) ValidateKey

func (m *Memory) ValidateKey(gatewayID string, key string) error

ValidateKey validates the access key for a gateway

type Redis

type Redis struct {
	Exchanger
	// contains filtered or unexported fields
}

Redis implements the authentication interface with a Redis backend

func (*Redis) Delete

func (r *Redis) Delete(gatewayID string) error

Delete gateway key and token

func (*Redis) GetToken

func (r *Redis) GetToken(gatewayID string) (string, error)

GetToken returns an access token for the gateway

func (*Redis) SetExchanger

func (r *Redis) SetExchanger(e Exchanger)

SetExchanger sets the component that will exchange access keys for access tokens

func (*Redis) SetKey

func (r *Redis) SetKey(gatewayID string, key string) error

SetKey sets the access key for a gateway

func (*Redis) SetToken

func (r *Redis) SetToken(gatewayID string, token string, expires time.Time) error

SetToken sets the access token for a gateway

func (*Redis) ValidateKey

func (r *Redis) ValidateKey(gatewayID string, key string) error

ValidateKey validates the access key for a gateway

Jump to

Keyboard shortcuts

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