basic

package
v7.0.0-...-807de66 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package basic 实现 Basic 校验

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

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

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

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

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

func SecurityScheme

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

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

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