temporary

package
v7.0.0-...-a39e3a1 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2025 License: MIT Imports: 9 Imported by: 1

Documentation

Overview

Package temporary 用于创建一个一次性的令牌

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SecurityScheme

func SecurityScheme(id string, desc web.LocaleStringer, query string) *openapi.SecurityScheme

SecurityScheme 声明支持 openapi 的 openapi.SecurityScheme 对象

Types

type Response

type Response struct {
	XMLName struct{} `json:"-" cbor:"-" xml:"token" yaml:"-"`
	Token   string   `json:"token" xml:"token" cbor:"token" comment:"access token"`                 // 访问令牌
	Expire  int      `json:"expire" xml:"expire,attr" cbor:"expire" comment:"access token expired"` // 访问令牌的有效时长,单位为秒
}

type Temporary

type Temporary[T any] struct {
	// contains filtered or unexported fields
}

func New

func New[T any](s web.Server, ttl time.Duration, once bool, query string, unauthProblemID, invalidTokenProblemID string) *Temporary[T]

New 创建 Temporary 对象

ttl 表示令牌的过期时间。 once 是否为一次性令牌,如果为 true,在验证成功之后,该令牌将自动失效; query 如果不为空,那么将由查询参数传递验证,否则表示 Bearer 类型的令牌传递; unauthProblemID 验证不通过时的错误代码; invalidTokenProblemID 令牌无效时返回的错误代码;

func (*Temporary[T]) GetInfo

func (t *Temporary[T]) GetInfo(ctx *web.Context) (T, bool)

func (*Temporary[T]) Logout

func (t *Temporary[T]) Logout(ctx *web.Context) error

func (*Temporary[T]) Middleware

func (t *Temporary[T]) Middleware(next web.HandlerFunc, method, _, _ string) web.HandlerFunc

func (*Temporary[T]) New

func (t *Temporary[T]) New(ctx *web.Context, v T, status int) web.Responser

New 创建令牌

v 为令牌关联的数据,之后通过验证接口可以访问该数据;

func (*Temporary[T]) QueryName

func (t *Temporary[T]) QueryName() string

QueryName 查询参数的名称

func (*Temporary[T]) SecurityScheme

func (t *Temporary[T]) SecurityScheme(id string, desc web.LocaleStringer) *openapi.SecurityScheme

Jump to

Keyboard shortcuts

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