auth

package
v2.3.0+incompatible Latest Latest
Warning

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

Go to latest
Published: May 9, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package auth provides authentication and authorization capability

Index

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

func ContextWithAccount(ctx context.Context, account *Account) (context.Context, error)

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

func Roles

func Roles(rs []*Role) func(o *GenerateOptions)

Roles 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

func AccountFromContext(ctx context.Context) (*Account, error)

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

func NewAuth

func NewAuth(opts ...Option) Auth

NewAuth returns a new default registry which is memory

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)

func Exclude

func Exclude(e ...string) Option

Exclude ecludes a set of endpoints from authorization

func LoginURL

func LoginURL(url string) Option

LoginURL sets the auth LoginURL

func PrivateKey

func PrivateKey(key string) Option

PrivateKey is the JWT private key

func Provider

func Provider(p provider.Provider) Option

Provider set the auth provider

func PublicKey

func PublicKey(key string) Option

PublicKey is the JWT public key

func Token

func Token(t string) Option

Token sets an auth token

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
}

type Resource

type Resource struct {
	// Name of the resource
	Name string
	// Type of resource, e.g.
	Type string
}

Resource is an entity such as a user or

type Role

type Role struct {
	// Name of the role
	Name string
	// The resource it has access
	// TODO: potentially remove
	Resource *Resource
}

Role an account has

Directories

Path Synopsis
Package provider is an external auth provider e.g oauth
Package provider is an external auth provider e.g oauth

Jump to

Keyboard shortcuts

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