basic

package
v6.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package basic 实现 Basic 校验

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetValue

func GetValue[T any](ctx *web.Context) (T, bool)

GetValue 获取当前对话关联的登录信息

func New

func New[T any](srv web.Server, auth AuthFunc[T], realm string, proxy bool) web.Middleware

New 声明一个 Basic 验证的中间件

proxy 是否为代理,主要是报头的输出内容不同,判断方式完全相同。 true 会输出 Proxy-Authorization 和 Proxy-Authenticate 报头和 407 状态码, 而 false 则是输出 Authorization 和 WWW-Authenticate 报头和 401 状态码;

T 表示验证成功之后,向用户传递的一些额外信息。之后可通过 [Basic.GetValue] 获取。

Types

type AuthFunc

type AuthFunc[T any] func(username, password []byte) (v T, ok bool)

AuthFunc 验证登录用户的函数签名

username,password 表示用户登录信息。 返回值中,ok 表示是否成功验证。如果成功验证, 则 v 为希望传递给用户的一些额外信息,比如登录用户的权限组什么的。

Jump to

Keyboard shortcuts

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