auth

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2019 License: GPL-3.0 Imports: 3 Imported by: 1

Documentation

Index

Constants

View Source
const SessionContextKey = "AuthSession"

SessionContextKey is the auth session context key

Variables

View Source
var (
	ErrTokenNotFound  = errors.New("Error finding token in request")
	ErrFetchUserData  = errors.New("Error fetching user data")
	ErrInvalidSession = errors.New("Invalid session")
)

Auth errors

Functions

This section is empty.

Types

type Credentials

type Credentials interface {
	GetProtocol() string
	GetIdentifier() string
	GetPassword() string
	GetHost() string
	GetPort() string
}

Credentials represents connection to a service having a protocol, identifier, password, host and port

type Endpoints

type Endpoints struct {
	Login          string `json:"login"`
	Logout         string `json:"logout"`
	Profile        string `json:"profile"`
	ForgetPassword string `json:"forget_password"`
	Register       string `json:"register"`
}

Endpoints is a list of common provider endpoints

type Options

type Options struct {
	AuthKey     string `json:"auth_key"`
	GuardianLib string `json:"guardian_lib"`
}

Options is a set options

type Provider

type Provider interface {
	// Name returns the name of provider
	Name() string

	// Options returns the provider options
	Options() *Options

	// SetOptions sets the provider options
	SetOptions(options *Options)

	// Endpoints returns the provider endpoints
	Endpoints() *Endpoints

	// SetEndpoints sets the provider endpoints
	SetEndpoints(endpoints *Endpoints)

	// Session returns a Session
	Session(req *http.Request) (Session, error)
}

Provider defines an auth interface

type ProviderFn

type ProviderFn func() Provider

ProviderFn returns an auth.Provider

type Providers

type Providers map[string]Provider

Providers is a map of provider name to Provider

type Session

type Session interface {
	// User returns the user info
	User() *User

	// IsAllowed returns whether user can perform an action
	IsAllowed(action string) bool
}

Session represents signature for a session

func GetSessionFromCtx

func GetSessionFromCtx(ctx context.Context) (Session, error)

GetSessionFromCtx returns session from context

type User

type User struct {
	RawData   map[string]interface{} `json:"raw_data"`
	Provider  string                 `json:"provider"` // Provider name
	Token     string                 `json:"-"`        // :sensitive:
	UserID    string                 `json:"user_id"`
	Username  string                 `json:"username"`
	Email     string                 `json:"email"`
	AvatarURL string                 `json:"avatar_url"`
	FirstName string                 `json:"first_name"`
	LastName  string                 `json:"last_name"`
	Location  string                 `json:"location"`
	Types     []string               `json:"types"`   // `Roles` for some Providers
	Actions   []string               `json:"actions"` // `Permissions` for some Providers
}

User contains the information common amongst most providers. All of the "raw" datafrom the provider can be found in the `RawData` field.

Jump to

Keyboard shortcuts

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