auth

package
v0.2024.5 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatSASURI

func FormatSASURI(hostname, deviceID, moduleID string) string

func GenerateSASToken

func GenerateSASToken(ctx context.Context, signer Signer, uri, policyName string, expires time.Time) (string, error)

GenerateSASToken will generate a token for accessing Azure IoT Hub, from a base64-encoded key. The token is scoped to a specific resource tree identified by uri - only resources which have uri as a prefix can be accessed with this token. Device SAS tokens must be device-scoped e.g. hubname.azure-devices.net/devices/device1 FormatSASURI can be used to generate an appropriate URI.

policyName is an optional shared access policy to referred to - omit when using device-registry credentials.

Algorithm specified at https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-dev-guide-sas?tabs=node

Types

type LocalSigner

type LocalSigner struct {
	Secret SASKey
}

func (*LocalSigner) Sign

func (s *LocalSigner) Sign(_ context.Context, data []byte) (signature []byte, err error)

type SASKey

type SASKey []byte

SASKey is a secret for performing HMAC operations. Standard textual representation is base64-encoded.

func ParseSASKey

func ParseSASKey(secret string) (SASKey, error)

func (SASKey) MarshalText

func (k SASKey) MarshalText() ([]byte, error)

func (*SASKey) UnmarshalText

func (k *SASKey) UnmarshalText(text []byte) error

type Signer

type Signer interface {
	Sign(ctx context.Context, data []byte) (signature []byte, err error)
}

Jump to

Keyboard shortcuts

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