biblio/auth/auth.go

49 lines
1.5 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package auth
import (
"time"
"github.com/gin-gonic/gin"
)
type AuthenticationRequest struct {
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
Token string `json:"token,omitempty"`
Captcha string `json:"captcha,omitempty"`
Phone string `json:"phone,omitempty"`
IP string `json:"ip,omitempty"`
}
type AuthenticationResponse struct {
Token string `json:"token,omitempty"`
UID uint64 `json:"uid,omitempty"`
Username string `json:"username,omitempty"`
Nickname string `json:"nickname,omitempty"`
Avatar string `json:"avatar,omitempty"`
Phone string `json:"phone,omitempty"`
Email string `json:"email,omitempty"`
CreatedAt uint `json:"created_at,omitempty"`
UpdatedAt uint `json:"updated_at,omitempty"`
Code int `json:"-"`
}
// type IdentifyResult struct {
// KubernetesToken string
// Cert string
// }
// 验证账号密码的方法这里想把这一块单独剥离出去这样不同的auth就更加抽象化
type IdentifyFunc func(*AuthenticationRequest) (*AuthenticationResponse, error)
type AuthManager interface {
Login(IdentifyFunc, *AuthenticationRequest) (*AuthenticationResponse, error)
Logout(*AuthenticationRequest) error
Refresh(*AuthenticationRequest) (string, error)
MiddleWare() gin.HandlerFunc
// InitAuthRoute(IdentifyFunc, *gin.RouterGroup)
ExpireAt(uint64, time.Time) error
Expire(uint64, time.Duration) error
TTL(uint64) (time.Duration, error)
}