base

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ServiceJwt = "jwt"
	TimeStamp  = "timestamp"

	CodeExpiry = "expiry"
	CodeFailed = "failed"
)
View Source
const (
	ErrAuthFailed       = "ErrAuthFailed"
	ErrEndpointNotFound = "EndpointNotFound"
)
View Source
const (
	WeChat            = "wechat"
	WeChatMiniProgram = "wechat_miniprogram"
	AliPay            = "alipay"
)
View Source
const (
	ServiceOAuth = "oauth"
)
View Source
const (
	ServiceTotp = "totp"
)

Variables

View Source
var Secret = "LijwefL(*IJWE)J@309j@#)(I#$@)(*"

Functions

This section is empty.

Types

type BaseOAuth

type BaseOAuth struct {
	Http      *resty.Client
	Endpoints map[string]Endpoint
}

func (*BaseOAuth) AddEndpoint

func (s *BaseOAuth) AddEndpoint(name string, endpoint Endpoint)

func (*BaseOAuth) GetEndpoint

func (s *BaseOAuth) GetEndpoint(name string) (*Endpoint, error)

func (*BaseOAuth) Init

func (s *BaseOAuth) Init()

func (*BaseOAuth) PreAuth

func (s *BaseOAuth) PreAuth(req *Request) (*Endpoint, error)

type Endpoint

type Endpoint struct {
	Provider  string `yaml:"type" json:"provider"`
	AppID     string `yaml:"appid" json:"appid"`
	AppSecret string `yaml:"secret" json:"secret"`
	PublicKey string `yaml:"publicKey" json:"publicKey"`
}

type IOAuthProvider

type IOAuthProvider interface {
	OAuth(req *Request) (*Response, error)
	Init()
	GetEndpoint(name string) (*Endpoint, error)
	AddEndpoint(name string, endpoint Endpoint)
}

type IServiceJwt

type IServiceJwt interface {
	Sign(claims jwt.MapClaims) (string, error)
	Validate(myClaims jwt.MapClaims, tokenStr string) (jwt.MapClaims, error)
	Parse(tokenStr string) (jwt.MapClaims, error)
	Refresh(tokenStr string) (string, error)
	SetSecret(secret string)
}

type IServiceOAuth

type IServiceOAuth interface {
	OAuth(req Request) (Response, error)
}

type IServiceTotp

type IServiceTotp interface {
	Gererate(endpoint string, account string) (string, string, error)
	Validate(endpoint string, code string, key string) (bool, error)
}

type Request

type Request struct {
	Provider       string `json:"provider"`
	Endpoint       string `json:"endpoint"`
	Code           string `json:"code"`
	AuthCodeMobile string
}

type Response

type Response struct {
	Type string `json:"type"`

	OpenID  string `json:"open_id"`
	UnionID string `json:"union_id"`
	Name    string `json:"name"`

	// 0:未知 1:男 2:女
	Gender int `json:"gender"`

	Province string `json:"province"`
	City     string `json:"city"`
	Country  string `json:"country"`
	Avatar   string `json:"avatar"`
	Mobile   string
}

Jump to

Keyboard shortcuts

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