authed

package
v1.4.5 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SubjectTypeAuthToken    string = "auth_token"
	SubjectTypeRefreshToken string = "refresh_token"
)

Variables

View Source
var ErrorInvalidPayload = errors.New("invalid payload")
View Source
var ErrorInvalidRefreshToken = errors.New("invalid refresh token")
View Source
var ErrorInvalidSession = errors.New("invalid session")
View Source
var ErrorInvalidToken = errors.New("invalid token")

Functions

This section is empty.

Types

type Authed

type Authed struct {
	Issuer               string
	Audience             []string // example: appname
	TokenDuration        time.Duration
	RefreshTokenDuration time.Duration
	MultiSession         bool
	// contains filtered or unexported fields
}

func NewAuthed

func NewAuthed(opts ...OptFunc) *Authed

func (*Authed) CreateToken

func (s *Authed) CreateToken(se *UserSession) (token, refresh string, err error)

func (*Authed) DeleteToken added in v1.4.2

func (s *Authed) DeleteToken(id string) (err error)

func (*Authed) DeleteTokenOnly added in v1.4.2

func (s *Authed) DeleteTokenOnly(id string) (err error)

func (*Authed) FormatLinkTokenStoreKey added in v1.4.2

func (s *Authed) FormatLinkTokenStoreKey(key string) string

func (*Authed) FormatRefreshTokenStoreKey

func (s *Authed) FormatRefreshTokenStoreKey(key string) string

func (*Authed) FormatTokenStoreKey

func (s *Authed) FormatTokenStoreKey(key string) string

func (*Authed) GetHTTPSession

func (s *Authed) GetHTTPSession(req *http.Request) (se *UserSession)

func (*Authed) NewClaims

func (s *Authed) NewClaims(subject string, se *UserSession, duration time.Duration) *Payload

func (*Authed) RefreshToken

func (s *Authed) RefreshToken(refreshToken string) (token, refresh string, err error)

func (*Authed) SetCookie

func (s *Authed) SetCookie(w http.ResponseWriter, key, value string, maxAge int)

func (*Authed) SetCookieToken

func (s *Authed) SetCookieToken(w http.ResponseWriter, value string, maxAge int)

func (*Authed) VerifyToken

func (s *Authed) VerifyToken(token string) (payload Payload, err error)

type OptFunc

type OptFunc func(session *Authed) *Authed

func WithCache added in v1.4.2

func WithCache(c cache.Cache) OptFunc

func WithCookieCode

func WithCookieCode(hashKey, key []byte) OptFunc

func WithCookieName

func WithCookieName(cookieName string) OptFunc

func WithCryptoKey added in v1.4.2

func WithCryptoKey(key []byte) OptFunc

WithCryptoKey 初始化加密jwt的hs512的密钥key

func WithJwtCode

func WithJwtCode(alg string) OptFunc

func WithMultiSession added in v1.4.2

func WithMultiSession() OptFunc

type Payload

type Payload struct {
	*UserSession
	codec.Payload
}

func (*Payload) SetExpired

func (p *Payload) SetExpired(t time.Time)

type SubjectType

type SubjectType string

type UserSession

type UserSession struct {
	OsName     string         `json:"os_name"`
	OsArch     string         `json:"os_arch"`
	ClientName string         `json:"client_name"`
	Username   string         `json:"username"`
	Nickname   string         `json:"nickname"`
	ID         string         `json:"id"`         // 会话ID
	Uid        string         `json:"uid"`        // 用户ID
	ExpiredAt  int64          `json:"expired_at"` // 单位秒,时间戳
	Roles      []string       `json:"roles,omitempty"`
	Scopes     []string       `json:"scopes,omitempty"`
	Extends    map[string]any `json:"extends,omitempty"`
	// contains filtered or unexported fields
}

UserSession 用户会话

func (*UserSession) GetIDInt64 added in v1.4.2

func (u *UserSession) GetIDInt64() int64

func (*UserSession) GetToken

func (u *UserSession) GetToken() string

func (*UserSession) GetUIDInt64 added in v1.4.2

func (u *UserSession) GetUIDInt64() int64

Jump to

Keyboard shortcuts

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