auth

package
v0.0.0-...-677ed08 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2016 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidAuth = fmt.Errorf("invalid authentication")
View Source
var (
	// ErrNoSerial indicates that a device serial is not set yet.
	ErrNoSerial = errors.New("no device serial yet")
)

Functions

func RemoveUser

func RemoveUser(st *state.State, userID int) error

RemoveUser removes a user from the state given its ID

func SetDevice

func SetDevice(st *state.State, device *DeviceState) error

SetDevice updates the device details in the state.

func UpdateUser

func UpdateUser(st *state.State, user *UserState) error

UpdateUser updates user in state

Types

type AuthContext

type AuthContext interface {
	Device() (*DeviceState, error)

	UpdateDeviceAuth(device *DeviceState, sessionMacaroon string) (actual *DeviceState, err error)

	UpdateUserAuth(user *UserState, discharges []string) (actual *UserState, err error)

	StoreID(fallback string) (string, error)

	DeviceSessionRequest(nonce string) (devSessionRequest []byte, serial []byte, err error)
}

An AuthContext exposes authorization data and handles its updates.

func NewAuthContext

func NewAuthContext(st *state.State, deviceAsserts DeviceAssertions) AuthContext

NewAuthContext returns an AuthContext for state.

type AuthState

type AuthState struct {
	LastID int          `json:"last-id"`
	Users  []UserState  `json:"users"`
	Device *DeviceState `json:"device,omitempty"`
}

AuthState represents current authenticated users as tracked in state

type DeviceAssertions

type DeviceAssertions interface {
	// Model returns the device model assertion.
	Model() (*asserts.Model, error)
	// Serial returns the device model assertion.
	Serial() (*asserts.Serial, error)

	// DeviceSessionRequest produces a device-session-request with the given nonce, it also returns the device serial assertion.
	DeviceSessionRequest(nonce string) (*asserts.DeviceSessionRequest, *asserts.Serial, error)
}

DeviceAssertions helps exposing the assertions about device identity. All methods should return state.ErrNoState if the underlying needed information is not (yet) available.

type DeviceState

type DeviceState struct {
	Brand  string `json:"brand,omitempty"`
	Model  string `json:"model,omitempty"`
	Serial string `json:"serial,omitempty"`

	KeyID string `json:"key-id,omitempty"`

	SessionMacaroon string `json:"session-macaroon,omitempty"`
}

DeviceState represents the device's identity and store credentials

func Device

func Device(st *state.State) (*DeviceState, error)

Device returns the device details from the state.

type UserState

type UserState struct {
	ID              int      `json:"id"`
	Username        string   `json:"username,omitempty"`
	Macaroon        string   `json:"macaroon,omitempty"`
	Discharges      []string `json:"discharges,omitempty"`
	StoreMacaroon   string   `json:"store-macaroon,omitempty"`
	StoreDischarges []string `json:"store-discharges,omitempty"`
}

UserState represents an authenticated user

func CheckMacaroon

func CheckMacaroon(st *state.State, macaroon string, discharges []string) (*UserState, error)

CheckMacaroon returns the UserState for the given macaroon/discharges credentials

func NewUser

func NewUser(st *state.State, username, macaroon string, discharges []string) (*UserState, error)

NewUser tracks a new authenticated user and saves its details in the state

func User

func User(st *state.State, id int) (*UserState, error)

User returns a user from the state given its ID

Jump to

Keyboard shortcuts

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