auth

package
v1.0.55 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	ActionLogin          = rbac.ActionLogin
	ActionSignUp         = rbac.ActionSignUp
	ActionResetPassword  = rbac.ActionResetPassword
	ActionChangePassword = rbac.ActionChangePassword
	ActionSendCode       = rbac.ActionSendCode
)

定义几种常用的授权动作

View Source
const (
	MechanismPassword = rbac.MechanismPassword
	MechanismEmail    = rbac.MechanismEmail
	MechanismPhone    = rbac.MechanismSMS
	MechanismSMS      = rbac.MechanismSMS
)

定义几种常用的验证机制

Variables

This section is empty.

Functions

This section is empty.

Types

type Authentication

type Authentication interface {
	Request

	Mechanism() string
	Account() string
	Secret() []byte
}

Authentication 表示一个身份验证请求

type AuthenticationBuilder added in v1.0.13

type AuthenticationBuilder struct {
	Context    context.Context
	Action     string
	Attributes attributes.Table
	Parameters parameters.Table
	Account    string
	Mechanism  string
	Secret     lang.Base64
	Step       string
	Feedback   Feedback
}

AuthenticationBuilder 用于创建 Authentication 实例

func (*AuthenticationBuilder) Create added in v1.0.13

func (inst *AuthenticationBuilder) Create() Authentication

Create 创建 Authentication 实例

type Authenticator

type Authenticator interface {

	// 验证用户身份
	Authenticate(a Authentication) ([]Identity, error)
}

Authenticator 表示一个身份验证算法

type AuthenticatorManager added in v1.0.22

type AuthenticatorManager interface {
	FindFor(a Authentication) (Authenticator, error)
	ListFor(a Authentication) []Authenticator
}

AuthenticatorManager ...

type Authorization

type Authorization interface {
	Request

	Identities() []Identity
}

Authorization 表示一个授权请求

type AuthorizationBuilder added in v1.0.10

type AuthorizationBuilder struct {
	Context    context.Context
	Attributes attributes.Table
	Parameters parameters.Table
	Action     string
	Step       string
	Identities []Identity
	Feedback   Feedback
}

AuthorizationBuilder 用来创建 Authorization

func (*AuthorizationBuilder) Create added in v1.0.10

func (inst *AuthorizationBuilder) Create() Authorization

Create ...

type Authorizer

type Authorizer interface {

	// 向用户授权
	Authorize(a Authorization) error
}

Authorizer 表示一个授权组件

type AuthorizerManager added in v1.0.22

type AuthorizerManager interface {
	FindFor(a Authorization) (Authorizer, error)
	ListFor(a Authorization) []Authorizer
}

AuthorizerManager ...

type EmailIdentity added in v1.0.24

type EmailIdentity interface {
	Identity

	Address() rbac.EmailAddress
}

EmailIdentity 表示基于 email address 的身份信息

func NewEmailIdentity added in v1.0.24

func NewEmailIdentity(by Authentication, info *rbac.EmailAddressDTO) EmailIdentity

NewEmailIdentity ...

type Feedback added in v1.0.54

type Feedback interface {
	Parameters() parameters.Table
}

Feedback ... 用于向请求方反馈验证信息

func NewFeedback added in v1.0.54

func NewFeedback() Feedback

NewFeedback 新建一个默认的 Feedback 对象

type Identity added in v1.0.22

type Identity interface {
	Class() string
	Name() string
	Mechanism() string
	By() Authentication
}

Identity 表示一个经过验证的身份

type Mechanism added in v1.0.14

type Mechanism interface {
	Support(r Request) bool
}

Mechanism 表示一个验证/授权机制组件

type PasswordCalculator

type PasswordCalculator struct {
	// contains filtered or unexported fields
}

PasswordCalculator 是默认的密码计算器

func (*PasswordCalculator) Compute

func (inst *PasswordCalculator) Compute(plain []byte) []byte

Compute 计算密码的哈希值

func (*PasswordCalculator) Reset added in v1.0.20

func (inst *PasswordCalculator) Reset() *PasswordCalculator

Reset ...

func (*PasswordCalculator) Verify

func (inst *PasswordCalculator) Verify(plain []byte) error

Verify 验证密码是否正确

func (*PasswordCalculator) WithSalt added in v1.0.20

func (inst *PasswordCalculator) WithSalt(salt []byte) *PasswordCalculator

WithSalt ...

func (*PasswordCalculator) WithTarget added in v1.0.20

func (inst *PasswordCalculator) WithTarget(target []byte) *PasswordCalculator

WithTarget ...

type PhoneIdentity added in v1.0.24

type PhoneIdentity interface {
	Identity

	FullNumber() rbac.FullPhoneNumber
}

PhoneIdentity 表示基于 phone number 的身份信息

func NewPhoneIdentity added in v1.0.24

func NewPhoneIdentity(by Authentication, info *rbac.PhoneNumberDTO) PhoneIdentity

NewPhoneIdentity ...

type Registration

type Registration struct {
	Authenticator Authenticator
	Authorizer    Authorizer
	Mechanism     Mechanism
	Priority      int
	Enabled       bool
}

Registration ... 注册信息

type Registry

type Registry interface {
	ListRegistrations() []*Registration
}

Registry ... 注册接口

type Request added in v1.0.14

type Request interface {
	Context() context.Context
	Attributes() attributes.Table
	Parameters() parameters.Table
	Feedback() Feedback
	Action() string
	Step() string
}

Request 包含 Authentication 和 Authorization 的公共方法

type Service

type Service interface {
	Authenticator

	Authorizer

	// 验证并授权
	Execute(r ...Request) error
}

Service ...

type UserIdentity added in v1.0.24

type UserIdentity interface {
	Identity

	UserName() rbac.UserName

	UserID() rbac.UserID

	Nickname() string

	Avatar() string

	Roles() rbac.RoleNameList
}

UserIdentity ...

func NewUserIdentity added in v1.0.24

func NewUserIdentity(by Authentication, info *rbac.UserDTO) UserIdentity

NewUserIdentity ...

Jump to

Keyboard shortcuts

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