Documentation
¶
Overview ¶
Package auth provides service-agnostic authentication orchestration.
Index ¶
- Constants
- Variables
- func HasPermission(identity *Identity, permission string) bool
- func RoleID(c identityContext) int64
- func UserID(c identityContext) int64
- type Auth
- func (a *Auth) Authenticate(ctx context.Context, credential string) (*Identity, error)
- func (a *Auth) Guard() Guard
- func (a *Auth) LoginByCredentials(ctx context.Context, credentials Credentials) (*LoginResult, error)
- func (a *Auth) Logout(ctx context.Context, credential string) error
- func (a *Auth) Mode() Mode
- type Credentials
- type Guard
- type HookFuncs
- func (h HookFuncs) AfterLogin(ctx context.Context, user any, identity *Identity) error
- func (h HookFuncs) AfterLoginFailed(ctx context.Context, username string, err error)
- func (h HookFuncs) BuildIdentity(ctx context.Context, user any) (*Identity, error)
- func (h HookFuncs) CheckPassword(ctx context.Context, user any, password string) error
- func (h HookFuncs) FindUser(ctx context.Context, username string) (any, error)
- type Hooks
- type Identity
- type JWTClaims
- type JWTConfig
- type JWTGuard
- type LoginResult
- type Mode
Constants ¶
View Source
const ( ContextIdentityKey = "auth.identity" ContextIdentity = ContextIdentityKey )
Variables ¶
Functions ¶
func HasPermission ¶
Types ¶
type Auth ¶
type Auth struct {
// contains filtered or unexported fields
}
var Default *Auth
Default is the global auth manager injected by bootstrap or service startup.
func NewWithGuard ¶
func (*Auth) Authenticate ¶
func (*Auth) LoginByCredentials ¶
func (a *Auth) LoginByCredentials(ctx context.Context, credentials Credentials) (*LoginResult, error)
type Credentials ¶
type HookFuncs ¶
type HookFuncs struct {
FindUserFunc func(ctx context.Context, username string) (any, error)
CheckPasswordFunc func(ctx context.Context, user any, password string) error
BuildIdentityFunc func(ctx context.Context, user any) (*Identity, error)
AfterLoginFunc func(ctx context.Context, user any, identity *Identity) error
AfterLoginFailedFunc func(ctx context.Context, username string, err error)
}
func (HookFuncs) AfterLogin ¶
func (HookFuncs) AfterLoginFailed ¶
func (HookFuncs) BuildIdentity ¶
func (HookFuncs) CheckPassword ¶
type Hooks ¶
type Hooks interface {
FindUser(ctx context.Context, username string) (any, error)
CheckPassword(ctx context.Context, user any, password string) error
BuildIdentity(ctx context.Context, user any) (*Identity, error)
AfterLogin(ctx context.Context, user any, identity *Identity) error
AfterLoginFailed(ctx context.Context, username string, err error)
}
type Identity ¶
type Identity struct {
SubjectID int64
SubjectType string
Username string
RoleID int64
Permissions []string
Extra map[string]any
}
func CurrentIdentity ¶
func CurrentIdentity(c identityContext) *Identity
type JWTClaims ¶
type JWTClaims = jwtx.SubjectClaims
type JWTGuard ¶
type JWTGuard struct {
// contains filtered or unexported fields
}
func NewJWTGuard ¶
func (*JWTGuard) Authenticate ¶
type LoginResult ¶
Source Files
¶
Click to show internal directories.
Click to hide internal directories.