validator

package
v0.0.0-...-7fbe588 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IClaimsValidator

type IClaimsValidator interface {
	jwt.IClaims
	Validate() error
}

IClaimsValidator 這是為了讓使用者可以自定義特殊欄位的驗證

type MyCustomClaims struct {
    jwt.RegisteredClaims // 這個包含標準的方法,你就不需要再自定義
    Foo string `json:"foo"`
}

func (m MyCustomClaims) Validate() error { // 自定義你的驗證邏輯
    if m.Foo != "bar" {
        return errors.New("must be foobar")
    }
    return nil
}

type Option

type Option func(v *Validator)

type Validator

type Validator struct {
	// timeFunc 驗證用的時間其基準,預設使用 time.Now()
	TimeFunc func() time.Time

	//require的項目表示,如果claims沒有提到此key,那麼是否要報錯
	RequireIssuer         bool // iss
	RequireSubject        bool // sub
	RequireAudience       bool // aud
	RequireExpirationTime bool // exp
	RequireNotBefore      bool // nbf
	RequireIssueAt        bool // iat

	// verify的項目,表示是否做該驗證
	VerifyIat bool

	ExpectedIssuer   string
	ExpectedSubject  string
	ExpectedAudience string
}

func (*Validator) Validate

func (v *Validator) Validate(iClaims jwt.IClaims) error

Jump to

Keyboard shortcuts

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