Documentation
¶
Index ¶
- Constants
- Variables
- type Authed
- func (s *Authed) CreateToken(se *UserSession) (token, refresh string, err error)
- func (s *Authed) DeleteToken(id string) (err error)
- func (s *Authed) DeleteTokenOnly(id string) (err error)
- func (s *Authed) FormatLinkTokenStoreKey(key string) string
- func (s *Authed) FormatRefreshTokenStoreKey(key string) string
- func (s *Authed) FormatTokenStoreKey(key string) string
- func (s *Authed) GetHTTPSession(req *http.Request) (se *UserSession)
- func (s *Authed) NewClaims(subject string, se *UserSession, duration time.Duration) *Payload
- func (s *Authed) RefreshToken(refreshToken string) (token, refresh string, err error)
- func (s *Authed) SetCookie(w http.ResponseWriter, key, value string, maxAge int)
- func (s *Authed) SetCookieToken(w http.ResponseWriter, value string, maxAge int)
- func (s *Authed) VerifyToken(token string) (payload Payload, err error)
- type OptFunc
- type Payload
- type SubjectType
- type UserSession
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 (*Authed) CreateToken ¶
func (s *Authed) CreateToken(se *UserSession) (token, refresh string, err error)
func (*Authed) DeleteToken ¶ added in v1.4.2
func (*Authed) DeleteTokenOnly ¶ added in v1.4.2
func (*Authed) FormatLinkTokenStoreKey ¶ added in v1.4.2
func (*Authed) FormatRefreshTokenStoreKey ¶
func (*Authed) FormatTokenStoreKey ¶
func (*Authed) GetHTTPSession ¶
func (s *Authed) GetHTTPSession(req *http.Request) (se *UserSession)
func (*Authed) RefreshToken ¶
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)
type OptFunc ¶
func WithCookieCode ¶
func WithCookieName ¶
func WithCryptoKey ¶ added in v1.4.2
WithCryptoKey 初始化加密jwt的hs512的密钥key
func WithJwtCode ¶
func WithMultiSession ¶ added in v1.4.2
func WithMultiSession() OptFunc
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
Click to show internal directories.
Click to hide internal directories.