auth

package
v2.0.0-...-96525d9 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidStrategy = errors.New("auth: Invalid strategy")

ErrInvalidStrategy is returned by Append/Revoke functions, when passed strategy does not implement Append/Revoke.

Functions

func Append

func Append(s Strategy, key interface{}, info Info) error

Append new Info to a strategy store. if passed strategy does not implement Append type ErrInvalidStrategy returned, Otherwise, nil.

WARNING: Append function does not guarantee safe concurrency, It's natively depends on strategy store.

func CtxWithUser

func CtxWithUser(ctx context.Context, info Info) context.Context

CtxWithUser Save user information in context.

func NewTypeError

func NewTypeError(prefix string, want, got interface{}) error

NewTypeError returns InvalidType error

func RequestWithUser

func RequestWithUser(info Info, r *http.Request) *http.Request

RequestWithUser Save user information in request context.

func Revoke

func Revoke(s Strategy, key interface{}) error

Revoke delete Info from strategy store. if passed strategy does not implement Revoke type ErrInvalidStrategy returned, Otherwise, nil.

WARNING: Revoke function does not guarantee safe concurrency, It's natively depends on strategy store.

func SetInfoConstructor

func SetInfoConstructor(c InfoConstructor)

SetInfoConstructor replace the default InfoConstructor with any function that has the appropriate signature. This allows the developers to create custom user info from their own struct instead of using the DefaultUser that go-guardian expose.

Default is NewDefaultUser

Types

type Cache

type Cache interface {
	// Load returns key value.
	Load(key interface{}) (interface{}, bool)
	// Store sets the key value.
	Store(key interface{}, value interface{})
	// StoreWithTTL sets the key value with TTL overrides the default.
	StoreWithTTL(key interface{}, value interface{}, ttl time.Duration)
	// Delete deletes the key value.
	Delete(key interface{})
}

Cache type describes the requirements for authentication strategies, that cache the authentication decisions.

type DefaultUser

type DefaultUser struct {
	Name       string
	ID         string
	Groups     []string
	Extensions Extensions
}

DefaultUser implement Info interface and provides a simple user information.

func NewDefaultUser

func NewDefaultUser(name, id string, groups []string, extensions Extensions) *DefaultUser

NewDefaultUser return new default user

func (*DefaultUser) GetExtensions

func (d *DefaultUser) GetExtensions() Extensions

GetExtensions return additional information.

func (*DefaultUser) GetGroups

func (d *DefaultUser) GetGroups() []string

GetGroups returns the names of the groups the user is a member of

func (*DefaultUser) GetID

func (d *DefaultUser) GetID() string

GetID returns a unique value identify a particular user

func (*DefaultUser) GetUserName

func (d *DefaultUser) GetUserName() string

GetUserName returns the name that uniquely identifies this user among all other active users.

func (*DefaultUser) SetExtensions

func (d *DefaultUser) SetExtensions(exts Extensions)

SetExtensions to contain additional information.

func (*DefaultUser) SetGroups

func (d *DefaultUser) SetGroups(groups []string)

SetGroups set the names of the groups the user is a member of.

func (*DefaultUser) SetID

func (d *DefaultUser) SetID(id string)

SetID set a unique value identify a particular user.

func (*DefaultUser) SetUserName

func (d *DefaultUser) SetUserName(name string)

SetUserName set the name that uniquely identifies this user among all other active users.

type Extensions

type Extensions map[string][]string

Extensions represents additional information to a user.

func (Extensions) Add

func (exts Extensions) Add(key, value string)

Add adds the key, value pair to the extensions. It appends to any existing values associated with key. The key is case sensitive.

func (Extensions) Clone

func (exts Extensions) Clone() Extensions

Clone returns a copy of extensions or nil if extensions is nil.

func (Extensions) Del

func (exts Extensions) Del(key string)

Del deletes the values associated with key.

func (Extensions) Get

func (exts Extensions) Get(key string) string

Get gets the first value associated with the given key. It is case sensitive; If there are no values associated with the key, Get returns "".

func (Extensions) Has

func (exts Extensions) Has(key string) bool

Has reports whether extensions has the provided key defined.

func (Extensions) Set

func (exts Extensions) Set(key, value string)

Set sets the extensions entries associated with key to the single element value. It replaces any existing values associated with key.

func (Extensions) Values

func (exts Extensions) Values(key string) []string

Values returns all values associated with the given key. It is case sensitive; The returned slice is not a copy.

type Info

type Info interface {
	// GetUserName returns the name that uniquely identifies this user among all
	// other active users.
	GetUserName() string
	// SetUserName set the name that uniquely identifies this user among all
	// other active users.
	SetUserName(string)
	// GetID returns a unique value identify a particular user.
	GetID() string
	// SetID set a unique value identify a particular user.
	SetID(string)
	// GetGroups returns the names of the groups the user is a member of
	GetGroups() []string
	// SetGroups set the names of the groups the user is a member of.
	SetGroups(groups []string)
	// Extensions can contain any additional information.
	GetExtensions() Extensions
	// SetExtensions to contain additional information.
	SetExtensions(exts Extensions)
}

Info describes a user that has been authenticated to the system.

func NewUserInfo

func NewUserInfo(name, id string, groups []string, extensions Extensions) Info

NewUserInfo implements InfoConstructor and return Info object. Typically called from strategies to create a new user object when its authenticated.

func User

func User(r *http.Request) Info

User return user information from request context.

func UserFromCtx

func UserFromCtx(ctx context.Context) Info

UserFromCtx return user information from context.

type InfoConstructor

type InfoConstructor func(name, id string, groups []string, extensions Extensions) Info

InfoConstructor define function signature to create new Info object.

type Option

type Option interface {
	Apply(v interface{})
}

Option configures Strategy using the functional options paradigm popularized by Rob Pike and Dave Cheney. If you're unfamiliar with this style, see https://commandcenter.blogspot.com/2014/01/self-referential-functions-and-design.html and https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis.

type OptionFunc

type OptionFunc func(v interface{})

OptionFunc implements Option interface.

func (OptionFunc) Apply

func (fn OptionFunc) Apply(v interface{})

Apply the configuration to the provided strategy.

type Strategy

type Strategy interface {
	// Authenticate users requests and return user information or error.
	Authenticate(ctx context.Context, r *http.Request) (Info, error)
}

Strategy represents an authentication mechanism or method to authenticate users requests.

type TypeError

type TypeError struct {
	Want string
	Got  string
	// contains filtered or unexported fields
}

TypeError represent invalid type assertion error.

func (TypeError) Error

func (i TypeError) Error() string

Error describe error as a string

Directories

Path Synopsis
Package claims collects common jwt types.
Package claims collects common jwt types.
Package internal contains support & helpers for go-guardian packages.
Package internal contains support & helpers for go-guardian packages.
jwt
strategies
basic
Package basic provides authentication strategy, to authenticate HTTP requests using the standard basic scheme.
Package basic provides authentication strategy, to authenticate HTTP requests using the standard basic scheme.
digest
Package digest provides authentication strategy, to authenticate HTTP requests using the standard digest scheme as described in RFC 7616.
Package digest provides authentication strategy, to authenticate HTTP requests using the standard digest scheme as described in RFC 7616.
jwt
Package jwt provides authentication strategy, to authenticate HTTP requests based on jwt token.
Package jwt provides authentication strategy, to authenticate HTTP requests based on jwt token.
kubernetes
Package kubernetes provide auth strategy to authenticate, incoming HTTP requests using a Kubernetes Service Account Token.
Package kubernetes provide auth strategy to authenticate, incoming HTTP requests using a Kubernetes Service Account Token.
ldap
Package ldap provides authentication strategy, to authenticate HTTP requests and builds, extracts user informations from LDAP Server.
Package ldap provides authentication strategy, to authenticate HTTP requests and builds, extracts user informations from LDAP Server.
oauth2/introspection
Package introspection provide auth strategy to authenticate, incoming HTTP requests using the oauth2 token introspection endpoint, as defined in RFC 7662.
Package introspection provide auth strategy to authenticate, incoming HTTP requests using the oauth2 token introspection endpoint, as defined in RFC 7662.
oauth2/jwt
Package jwt provides authentication strategy, incoming HTTP requests using the oauth2 jwt access token or openid IDToken.
Package jwt provides authentication strategy, incoming HTTP requests using the oauth2 jwt access token or openid IDToken.
oauth2/userinfo
Package userinfo provide auth strategy to authenticate, incoming HTTP requests using the oauth2/openid userinfo endpoint, as defined in OpenID Connect https://openid.net/specs/openid-connect-core-1_0.html#UserInfo.
Package userinfo provide auth strategy to authenticate, incoming HTTP requests using the oauth2/openid userinfo endpoint, as defined in OpenID Connect https://openid.net/specs/openid-connect-core-1_0.html#UserInfo.
opaque
Package opaque provides server-side consistent tokens.
Package opaque provides server-side consistent tokens.
token
Package token provides authentication strategy, to authenticate HTTP requests based on token.
Package token provides authentication strategy, to authenticate HTTP requests based on token.
twofactor
Package twofactor provides authentication strategy, to authenticate HTTP requests based on one time password(otp).
Package twofactor provides authentication strategy, to authenticate HTTP requests based on one time password(otp).
x509
Package x509 provides authentication strategy, to authenticate HTTPS requests and builds, extracts user informations from client certificates.
Package x509 provides authentication strategy, to authenticate HTTPS requests and builds, extracts user informations from client certificates.

Jump to

Keyboard shortcuts

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