ttnauth

package
v0.0.0-...-80ab217 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package ttnauth implements MQTT authentication using The Things Network's account server

Index

Constants

View Source
const IDRegexp = "[0-9a-z](?:[_-]?[0-9a-z]){1,35}"

IDRegexp is the regular expression that matches TTN IDs

Variables

View Source
var DefaultCacheExpire = time.Minute

DefaultCacheExpire sets the expiration time of the cache

View Source
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

View Source
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

func (Access) IsEmpty

func (a Access) IsEmpty() bool

IsEmpty returns true if there is no access

type Cache

type Cache interface {
	GetOrFetch(username string, password []byte, fetch func(username string, password []byte) (*Access, error)) (*Access, error)
}

type TTNAuth

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

TTNAuth implements authentication for TTN

func New

func New(servers map[string]string) *TTNAuth

New returns a new auth interface that uses the TTN account server

func (*TTNAuth) AddSuperUser

func (a *TTNAuth) AddSuperUser(username string, password []byte, access Access)

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) CanRead

func (a *TTNAuth) CanRead(info *auth.Info, t ...string) bool

CanRead returns true iff the session can read from the topic

func (*TTNAuth) CanWrite

func (a *TTNAuth) CanWrite(info *auth.Info, t ...string) bool

CanWrite returns true iff the session can write to the topic

func (*TTNAuth) Connect

func (a *TTNAuth) Connect(ctx context.Context, info *auth.Info) (context.Context, error)

Connect or return error code

func (*TTNAuth) FetchAccess

func (a *TTNAuth) FetchAccess(username string, password []byte) (*Access, error)

func (*TTNAuth) SetCacheExpire

func (a *TTNAuth) SetCacheExpire(expires time.Duration)

SetCacheExpire sets the cache expiration time. By default, the DefaultCacheExpire is used

func (*TTNAuth) SetLogger

func (a *TTNAuth) SetLogger(logger log.Interface)

SetLogger sets the logger interface. By default, the Noop logger is used

func (*TTNAuth) SetPenalty

func (a *TTNAuth) SetPenalty(d time.Duration)

SetPenalty sets the time penalty for a failed login

func (*TTNAuth) SetRateLimit

func (a *TTNAuth) SetRateLimit(l rate.Limit)

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.

Jump to

Keyboard shortcuts

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