auth

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: 3 Imported by: 6

Documentation

Overview

Package auth defines the authentication interface for MQTT.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContextWithInterface

func NewContextWithInterface(ctx context.Context, auth Interface) context.Context

NewContextWithInterface returns a new context that contains the interface

Types

type Info

type Info struct {
	Interface
	RemoteAddr string
	Transport  string
	ServerName string
	ClientID   string
	Username   string
	Password   []byte
	Metadata   interface{}
}

Info for an MQTT user

func (*Info) CanRead

func (i *Info) CanRead(t ...string) bool

CanRead returns true iff given the info, the client can read on a topic

func (*Info) CanWrite

func (i *Info) CanWrite(t ...string) bool

CanWrite returns true iff given the info, the client can write on a topic

func (*Info) Subscribe

func (i *Info) Subscribe(requestedTopic string, requestedQoS byte) (acceptedTopic string, acceptedQoS byte, err error)

Subscribe to the requested topic and QoS, which can be adapted by the auth plugin

type Interface

type Interface interface {
	// Connect, extend context or return error code
	Connect(ctx context.Context, info *Info) (context.Context, 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.
	Subscribe(info *Info, requestedTopic string, requestedQoS byte) (acceptedTopic string, acceptedQoS byte, err error)

	// Can the session read from the (application-layer) topic
	CanRead(info *Info, topic ...string) bool

	// Can the session write to the (application-layer) topic
	CanWrite(info *Info, topic ...string) bool
}

Interface for MQTT authentication

func InterfaceFromContext

func InterfaceFromContext(ctx context.Context) Interface

InterfaceFromContext returns the auth interface from the context

Directories

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

Jump to

Keyboard shortcuts

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