auth

package
v0.0.0-...-cbea63e Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2021 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BadCredentialsError error = errors.New("Bad credentials")
)
View Source
var RoleGlobOptions = &glob.Options{
	Separator:    '.',
	MatchAtStart: true,
	MatchAtEnd:   true,
}

Options which should be used whenever construting a role glob

Functions

func Auth

func Auth(mech, device string, creds map[string]string) error

Auth wraps defaultScope.Auth

func Clean

func Clean()

Clean wraps defaultScope.Clean

func HasAccess

func HasAccess(role string) bool

HasAccess wraps defaultScope.HasAccess

func Invalidate

func Invalidate(sessId string) error

Invalidate wraps `Invalidate` against our default memcache-based `Cacher`

func IsAuth

func IsAuth() bool

IsAuth wraps defaultScope.IsAuth

func RecoverService

func RecoverService(toEndpoint, fromService string) error

RecoverService wraps defaultScope.RecoverService

func RecoverSession

func RecoverSession(sessId string) error

RecoverSession wraps defaultScope.RecoverSession

func SetCurrentService

func SetCurrentService(name string)

SetCurrentService defines the current service, as used for service-to-service auth This defines who _we_ are, and thus which rules we'll load that define which other services will be allowed via HasAccess to call us with assumed role auth TODO delete when removing s2s rules

func SignOut

func SignOut(user *User)

SignOut wraps defaultScope.SignOut

Types

type Cacher

type Cacher interface {
	Store(u *User) error
	Invalidate(sessId string) error
	Fetch(sessId string) (u *User, cacheHit bool, err error)
	Purge(sessId string) error
}

type MockScope

type MockScope struct {
	MockUid   string
	MockRoles []string
	// contains filtered or unexported fields
}

func (*MockScope) Auth

func (s *MockScope) Auth(mech, device string, creds map[string]string) error

func (*MockScope) AuthUser

func (s *MockScope) AuthUser() *User

func (*MockScope) Authorised

func (s *MockScope) Authorised() bool

func (*MockScope) Clean

func (s *MockScope) Clean() Scope

func (*MockScope) HasAccess

func (s *MockScope) HasAccess(role string) bool

func (*MockScope) HasTriedAuth

func (s *MockScope) HasTriedAuth() bool

func (*MockScope) IsAuth

func (s *MockScope) IsAuth() bool

func (*MockScope) MockUser

func (s *MockScope) MockUser(id string, roles []string)

func (*MockScope) RecoverService

func (s *MockScope) RecoverService(toEndpoint, fromService string) error

func (*MockScope) RecoverSession

func (s *MockScope) RecoverSession(sessId string) error

func (*MockScope) RpcScope

func (s *MockScope) RpcScope(scoper multiclient.Scoper) Scope

func (*MockScope) SetAuthorised

func (s *MockScope) SetAuthorised(authorised bool)

func (*MockScope) SignOut

func (s *MockScope) SignOut(user *User) error

type Scope

type Scope interface {
	RpcScope(scoper multiclient.Scoper) Scope
	Clean() Scope
	RecoverSession(sessId string) error
	RecoverService(toEndpoint, fromService string) error
	Auth(mech, device string, creds map[string]string) error
	IsAuth() bool
	AuthUser() *User
	HasAccess(role string) bool
	SignOut(user *User) error
	HasTriedAuth() bool
	Authorised() bool
	SetAuthorised(authorised bool)
}

Scope represents some session witin which we may know about a user who has somehow identified themselves to us, or some service that has identified itself to us (and we trust)

func New

func New() Scope

New mints a new scope

type User

type User struct {
	SessId, Mech, Device, Id     string
	CreatedTs, ExpiryTs, RenewTs time.Time
	Roles                        []string
	Token, Sig, Data             []byte
}

func AuthUser

func AuthUser() *User

AuthUser wraps defaultScope.AuthUser

func FromSessionToken

func FromSessionToken(s, t string) (*User, error)

FromSessionToken turns a raw session and token pair into a full user object that we can query/validate

func (*User) Application

func (u *User) Application() string

Application returns the user's application (derived from the authentication mechanism). This is only available for H2-generated tokens; H1 tokens return an empty string.

func (*User) CanAutoRenew

func (u *User) CanAutoRenew() bool

CanAutoRenew tests if the token can be auto-renewed at this time (by the login service)

func (*User) HasRole

func (u *User) HasRole(r string) bool

HasRole tests if the user has this role we test roles against the hierarchy, eg: you could have FOO.BAR where the most specific role is FOO.BAR but FOO automatically covers FOO.BAR

Jump to

Keyboard shortcuts

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