grants

package
v0.0.0-...-692b37b Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2022 License: MIT Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Errors
	ErrRequestGrant = errors.New("Request does not match grant")
)
View Source
var GrantStrings = map[Grant]string{
	GrantUnknown:      "unknown",
	GrantNone:         "none",
	GrantSetOTP:       "otp",
	GrantOTPValidate:  "otp-validate",
	GrantOTPQR:        "otp-qr",
	GrantUsersRefresh: "users-refresh",
	GrantKeysRegister: "keys-register",

	GrantOTP:           "otp-all",
	GrantAuthenticated: "authenticated",
}

GrantStrings map a basic access grant to a string representation.

Functions

func ContainsGrant

func ContainsGrant(grant Grant, r *http.Request) error

ContainsGrant return nil if the given request's context contains the given access grant. Otherwise an error is returned.

func IsCustomGrantsSet

func IsCustomGrantsSet() bool

IsCustomGrantsSet is a conveniance function that returns true if custom user grants are set.

func SetCustomGrants

func SetCustomGrants(grants []string) error

SetCustomGrants sets additional user grants. The number of grants are limited by MaxCustomGrants. Using this function will remove any existing custom grants.

Types

type Grant

type Grant uint64

Grant represents an access grant for interacting with the authentication service.

const (
	GrantDelimiter  = ","
	MaxCustomGrants = 8 // bits

	// Grant Sections
	GrantSectionOTP      Grant = 0x00000000000000FE
	GrantSectionUsers    Grant = 0x000000000000FF00
	GrantSectionKeys     Grant = 0x0000000000FF0000
	GrantSectionCustom   Grant = 0x00000000FF000000
	GrantSectionReserved Grant = 0xFFFFFFFF00000000

	// No grants
	GrantUnknown Grant = 0x00000000
	GrantNone    Grant = 0x00000001

	// OTP grants
	GrantSetOTP      Grant = 0x00000002
	GrantOTPValidate Grant = 0x00000004
	GrantOTPQR       Grant = 0x00000008
	GrantOTP         Grant = GrantSetOTP | GrantOTPValidate | GrantOTPQR

	// User grants
	GrantUsersRefresh Grant = 0x00000100
	GrantUsers        Grant = GrantUsersRefresh

	// Key grants
	GrantKeysRegister Grant = 0x00010000
	GrantKeys         Grant = GrantKeysRegister

	// Authenticated grants
	GrantAuthenticated Grant = GrantOTP | GrantUsers | GrantKeys

	// Reserved
	GrantFull Grant = 0xFFFFFFFE
	GrantMax  Grant = 0xFFFFFFFF
)

func GetCustomGrant

func GetCustomGrant(grant ...string) Grant

GetCustomGrant returns the custom user grants currently set. Passing grant names will limit the result to those grants.

func ToGrant

func ToGrant(s string) (Grant, error)

ToGrant returns an access grant for the given string. The string may be comma-separated to include multiple grants; E.g. "otp-validate,otp-qr".

func (Grant) Clean

func (g Grant) Clean() Grant

Clean returns a grant "cleansed" of unused/reserved bits. If the grant contains a self-terminating grant (E.g. GrantNone), that is returned instead.

func (Grant) Short

func (g Grant) Short() string

Short returns the short name of the access grant. If the grant is not mapped to a short name, a comma-separated string representation is returned instead (IE. Grant.String() is called instead).

func (Grant) String

func (g Grant) String() string

String returns the comma-separated string representation of the access grant.

Jump to

Keyboard shortcuts

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