authcli

package
v0.0.0-...-9ed2a0c Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2024 License: MIT Imports: 12 Imported by: 2

Documentation

Index

Constants

View Source
const UserCtxKey = "UserID"

Variables

View Source
var (
	ErrValidateRemoteStatusFailed = irr.Error("validate remote status failed")
	ErrValidateRemoteDegraded     = irr.Error("validate remote degraded")
)

Functions

func GetUIDFromGinCtx

func GetUIDFromGinCtx(c *gin.Context) (userID uint64, exists bool)

GetUIDFromGinCtx read the uid form gin-context

Types

type Cli

type Cli struct {
	AuthNSvrURL string
	// contains filtered or unexported fields
}

Cli represents the client used to interact with the IAM server and perform local JWT verification

func New

func New(secretKey, sessionServiceURL string) *Cli

New creates a new instance of the IAM client

func (*Cli) AuthN

func (cli *Cli) AuthN(ctx context.Context, tokenStr string) (uint64, error)

AuthN 从 jwt 中直接获取 user_id 信息

func (*Cli) GinMW

func (cli *Cli) GinMW() gin.HandlerFunc

GinMW 创建一个检查 JWT 是否有效的 Gin 中间件

func (*Cli) RefreshToken

func (cli *Cli) RefreshToken(refreshToken string) (string, error)

RefreshToken sends a refresh token request to IAM and returns a new token

func (*Cli) ValidateRemote

func (cli *Cli) ValidateRemote(ctx context.Context, token string) (uint64, error)

ValidateRemote tries to validate the token with the IAM server first. If the IAM server is unavailable or gives a degraded response, it performs local JWT validation (long term ticket). Otherwise, it opts for the short ticket.

Jump to

Keyboard shortcuts

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