authenticator

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package authenticator 用户验证

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrExists = errors.New("user already exists")

	ErrUnauthorized = errors.New("unauthorized")
)

Functions

This section is empty.

Types

type Authenticator

type Authenticator interface {
	// Valid 验证账号
	//
	// username, password 向验证器提供的登录凭证,不同的实现对此两者的定义可能是不同的,
	// 比如 oauth2 中表示的是由 authURL 返回的 state 和 code 参数。
	// ok 表示是否验证成功;
	// uid 表示验证成功之后返回与 username 关联的用户 ID;
	// identity 表示验证成功,但是并未与任何 uid 绑定时,则返回该验证器验证之后的用户标记;
	Valid(username, password string) (uid int64, identity string, ok bool)

	// Identity 获取 uid 关联的账号名
	Identity(int64) (string, bool)
}

Authenticator 身份验证接口

type Authenticators

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

Authenticators 验证器管理

func NewAuthenticators

func NewAuthenticators(s *web.Server, d time.Duration, jobTitle string) *Authenticators

NewAuthenticators 声明 Authenticators 对象

d 每个验证失败的 ID 过期时间同时也是回收的频率; jobTitle 回收方法的名称;

func (*Authenticators) All

func (a *Authenticators) All(p *message.Printer) map[string]string

All 返回所有的验证器

func (*Authenticators) GC

func (a *Authenticators) GC(now time.Time) error

GC 执行回收过期 identity 的方法

func (*Authenticators) Identities

func (a *Authenticators) Identities(uid int64) map[string]string

Identities 获取 uid 已经关联的验证器

返回值键名为验证器 id,键值为该验证器对应的账号。

func (*Authenticators) IdentityExpired

func (a *Authenticators) IdentityExpired(id, identity string) bool

IdentityExpired 验证由 [Authenticator.Valid] 返回的值是否还能使用

func (*Authenticators) Register

func (a *Authenticators) Register(id string, auth Authenticator, name web.LocaleStringer)

Register 注册验证器

id 为验证器的类型名称,需要唯一; name 为该验证器的本地化名称; logo 为该验证器的 LOGO;

func (*Authenticators) Valid

func (a *Authenticators) Valid(id, identity, password string) (int64, string, bool)

Valid 验证账号密码

id 表示通过 Authenticators.Register 注册验证器时的 id;

Directories

Path Synopsis
Package custom 自定义验证方法
Package custom 自定义验证方法
Package email 邮件验证
Package email 邮件验证
Package oauth 提供基于 [OAuth2] 的登录和注册功能
Package oauth 提供基于 [OAuth2] 的登录和注册功能
Package password 密码类型的验证器
Package password 密码类型的验证器

Jump to

Keyboard shortcuts

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