Documentation ¶
Overview ¶
Package auth provides authentication and authorization capability
Index ¶
- Constants
- Variables
- func ContextWithAccount(ctx context.Context, account *Account) (context.Context, error)
- func Expiry(ex time.Time) func(o *GenerateOptions)
- func Metadata(md map[string]string) func(o *GenerateOptions)
- func Roles(rs []*Role) func(o *GenerateOptions)
- type Account
- type Auth
- type GenerateOption
- type GenerateOptions
- type Option
- type Options
- type Resource
- type Role
Constants ¶
View Source
const ( // MetadataKey is the key used when storing the account // in metadata MetadataKey = "auth-account" // CookieName is the name of the cookie which stores the // auth token CookieName = "micro-token" )
Variables ¶
View Source
var (
DefaultAuth = NewAuth()
)
Functions ¶
func ContextWithAccount ¶
ContextWithAccount sets the account in the context
func Expiry ¶
func Expiry(ex time.Time) func(o *GenerateOptions)
Expiry for the generated account's token expires
func Metadata ¶
func Metadata(md map[string]string) func(o *GenerateOptions)
Metadata for the generated account
Types ¶
type Account ¶
type Account struct { // ID of the account (UUIDV4, email or username) Id string `json:"id"` // Token used to authenticate Token string `json:"token"` // Time of Account creation Created time.Time `json:"created"` // Time of Account expiry Expiry time.Time `json:"expiry"` // Roles associated with the Account Roles []*Role `json:"roles"` // Any other associated metadata Metadata map[string]string `json:"metadata"` }
Account provided by an auth provider
func AccountFromContext ¶
AccountFromContext gets the account from the context, which is set by the auth wrapper at the start of a call. If the account is not set, a nil account will be returned. The error is only returned when there was a problem retrieving an account
type Auth ¶
type Auth interface { // Init the auth package Init(opts ...Option) error // Options returns the options set Options() Options // Generate a new auth Account Generate(id string, opts ...GenerateOption) (*Account, error) // Revoke an authorization Account Revoke(token string) error // Verify an account token Verify(token string) (*Account, error) // String returns the implementation String() string }
Auth providers authentication and authorization
type GenerateOption ¶
type GenerateOption func(o *GenerateOptions)
type GenerateOptions ¶
type GenerateOptions struct { // Metadata associated with the account Metadata map[string]string // Roles/scopes associated with the account Roles []*Role //Expiry of the token Expiry time.Time }
func NewGenerateOptions ¶
func NewGenerateOptions(opts ...GenerateOption) GenerateOptions
NewGenerateOptions from a slice of options
type Option ¶
type Option func(o *Options)
type Options ¶
type Options struct { // Token is an auth token Token string // Public key base64 encoded PublicKey string // Private key base64 encoded PrivateKey string // Endpoints to exclude Exclude []string // Provider is an auth provider Provider provider.Provider // LoginURL is the relative url path where a user can login LoginURL string }
Click to show internal directories.
Click to hide internal directories.