goauth

package module
v0.0.0-...-6e47d70 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2021 License: Unlicense Imports: 19 Imported by: 0

README

go-auth

Authentication library for Go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateJWT

func GenerateJWT(id string, data map[string]string) string

func GenerateRefreshToken

func GenerateRefreshToken(id string) string

func GenerateToken

func GenerateToken(id string) string

Types

type AuthClient

type AuthClient struct {
	ClienId      string            `json:"client_id"`
	UserId       string            `json:"user_id"`
	Token        string            `json:"token"`
	RefreshToken string            `json:"refresh_token"`
	CreatedTime  time.Time         `json:"created_at"`
	ExpiredTime  time.Time         `json:"expired_at"`
	ExpiredIn    int               `json:"expired_in"`
	Scope        string            `json:"scope"`
	TokenType    string            `json:"token_type"`
	JWT          string            `json:"jwt"`
	UserData     map[string]string `json:"-"`
}

type GoAuth

type GoAuth struct {
	RedisTokenKey  string
	RedisUserKey   string
	RedisExpiredIn int
	RedisClient    *redis.Client
	TokenType      string
}

func (*GoAuth) CheckClientInRedis

func (g *GoAuth) CheckClientInRedis(client AuthClient) (AuthClient, error)

func (*GoAuth) CheckTokenInRedis

func (g *GoAuth) CheckTokenInRedis(token string) (AuthClient, error)

func (*GoAuth) ClientCredential

func (g *GoAuth) ClientCredential(client AuthClient, isRefresh bool) (AuthClient, error)

func (*GoAuth) CreateClient

func (g *GoAuth) CreateClient(client AuthClient) AuthClient

func (*GoAuth) CreateClientResponse

func (g *GoAuth) CreateClientResponse(client AuthClient, isRefresh bool) (AuthClient, error)

func (*GoAuth) DeleteClientFromRedis

func (g *GoAuth) DeleteClientFromRedis(client AuthClient) error

func (*GoAuth) GetTokenFromRedis

func (g *GoAuth) GetTokenFromRedis(clientId string) (interface{}, error)

func (*GoAuth) GetUserFromRedis

func (g *GoAuth) GetUserFromRedis(clientId string) (interface{}, error)

func (*GoAuth) InsertClientToRedis

func (g *GoAuth) InsertClientToRedis(client AuthClient) error

type GoAuthMiddleware

type GoAuthMiddleware struct {
	GoAuth        IGoAuth
	CacheObj      libcache.Cache
	Strategy      union.Union
	TokenStrategy auth.Strategy
}

func NewAuthMiddleware

func NewAuthMiddleware(client IGoAuth) (*GoAuthMiddleware, error)

func (*GoAuthMiddleware) GinAuthMiddleware

func (ig *GoAuthMiddleware) GinAuthMiddleware() gin.HandlerFunc

func (*GoAuthMiddleware) SetupGoAuthMiddleware

func (ig *GoAuthMiddleware) SetupGoAuthMiddleware()

func (*GoAuthMiddleware) SetupStrategies

func (ig *GoAuthMiddleware) SetupStrategies(strategies ...auth.Strategy)

func (*GoAuthMiddleware) ValidateBasicAuth

func (ig *GoAuthMiddleware) ValidateBasicAuth(ctx context.Context, r *http.Request, username, password string) (auth.Info, error)

func (*GoAuthMiddleware) ValidateTokenAuth

func (ig *GoAuthMiddleware) ValidateTokenAuth(ctx context.Context, r *http.Request, tokenString string) (auth.Info, time.Time, error)

type IGoAuth

type IGoAuth interface {
	GetTokenFromRedis(clientId string) (interface{}, error)
	GetUserFromRedis(clientId string) (interface{}, error)
	InsertClientToRedis(client AuthClient) error
	DeleteClientFromRedis(client AuthClient) error
	ClientCredential(client AuthClient, isRefresh bool) (AuthClient, error)
	CheckClientInRedis(client AuthClient) (AuthClient, error)
	CheckTokenInRedis(token string) (AuthClient, error)
	CreateClient(client AuthClient) AuthClient
	CreateClientResponse(client AuthClient, isRefresh bool) (AuthClient, error)
}

func NewGoAuth

func NewGoAuth(client GoAuth) (IGoAuth, error)

Jump to

Keyboard shortcuts

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