Documentation ¶
Overview ¶
Package ttnauth implements MQTT authentication using The Things Network's account server
Index ¶
- Constants
- Variables
- type Access
- type Cache
- type TTNAuth
- func (a *TTNAuth) AddSuperUser(username string, password []byte, access Access)
- func (a *TTNAuth) AuthenticateApplications()
- func (a *TTNAuth) AuthenticateGateways()
- func (a *TTNAuth) CanRead(info *auth.Info, t ...string) bool
- func (a *TTNAuth) CanWrite(info *auth.Info, t ...string) bool
- func (a *TTNAuth) Connect(ctx context.Context, info *auth.Info) (context.Context, error)
- func (a *TTNAuth) FetchAccess(username string, password []byte) (*Access, error)
- func (a *TTNAuth) SetCacheExpire(expires time.Duration)
- func (a *TTNAuth) SetLogger(logger log.Interface)
- func (a *TTNAuth) SetPenalty(d time.Duration)
- func (a *TTNAuth) SetRateLimit(l rate.Limit)
- func (a *TTNAuth) Subscribe(info *auth.Info, requestedTopic string, requestedQoS byte) (acceptedTopic string, acceptedQoS byte, err error)
Constants ¶
const IDRegexp = "[0-9a-z](?:[_-]?[0-9a-z]){1,35}"
IDRegexp is the regular expression that matches TTN IDs
Variables ¶
var DefaultCacheExpire = time.Minute
DefaultCacheExpire sets the expiration time of the cache
var HandlerAccess = Access{ Read: [][]string{ {topic.PartWildcard, "devices", topic.PartWildcard, "down"}, }, Write: [][]string{ {topic.PartWildcard, "devices", topic.PartWildcard, "up"}, {topic.PartWildcard, "devices", topic.PartWildcard, "up", topic.Wildcard}, {topic.PartWildcard, "devices", topic.PartWildcard, "events"}, {topic.PartWildcard, "devices", topic.PartWildcard, "events", topic.Wildcard}, {topic.PartWildcard, "events"}, {topic.PartWildcard, "events", topic.Wildcard}, }, }
HandlerAccess gives the access rights for a Handler
var RouterAccess = Access{ Read: [][]string{ {"connect"}, {"disconnect"}, {topic.PartWildcard, "up"}, {topic.PartWildcard, "status"}, }, Write: [][]string{ {topic.PartWildcard, "down"}, }, }
RouterAccess gives the access rights for a Router
Functions ¶
This section is empty.
Types ¶
type Access ¶
type Access struct { Root bool ReadPrefix string // must not contain `/` Read [][]string Write [][]string }
Access information
type TTNAuth ¶
type TTNAuth struct {
// contains filtered or unexported fields
}
TTNAuth implements authentication for TTN
func (*TTNAuth) AddSuperUser ¶
AddSuperUser adds a super-user to the auth plugin
func (*TTNAuth) AuthenticateApplications ¶
func (a *TTNAuth) AuthenticateApplications()
AuthenticateApplications enables authentication of applications
func (*TTNAuth) AuthenticateGateways ¶
func (a *TTNAuth) AuthenticateGateways()
AuthenticateGateways enables authentication of gateways
func (*TTNAuth) FetchAccess ¶
func (*TTNAuth) SetCacheExpire ¶
SetCacheExpire sets the cache expiration time. By default, the DefaultCacheExpire is used
func (*TTNAuth) SetLogger ¶
SetLogger sets the logger interface. By default, the Noop logger is used
func (*TTNAuth) SetPenalty ¶
SetPenalty sets the time penalty for a failed login
func (*TTNAuth) SetRateLimit ¶
SetRateLimit sets the rate limit for non-super-users.
func (*TTNAuth) Subscribe ¶
func (a *TTNAuth) Subscribe(info *auth.Info, requestedTopic string, requestedQoS byte) (acceptedTopic string, acceptedQoS byte, err error)
Subscribe allows the auth plugin to replace wildcards or to lower the QoS of a subscription. For example, a client requesting a subscription to "#" may be rewritten to "foo/#" if they are only allowed to subscribe to that topic.