auth

package
v2.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2025 License: BSD-3-Clause Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AlgHS256 = "HS256"
	AlgHS384 = "HS384"
	AlgHS512 = "HS512"
)
View Source
const CodeGoogle = "google"
View Source
const CodeYandex = "yandex"

Variables

This section is empty.

Functions

func JWTPayloadContext

func JWTPayloadContext(c tContext, payload interface{}) error

func WithJWT

func WithJWT() plugins.Plugin

WithJWT init jwt provider

func WithOAuth

func WithOAuth(opts ...func(OAuthOption)) plugins.Plugin

WithOAuth init oauth providers

Types

type Config

type Config struct {
	Code         string `yaml:"code"`
	ClientID     string `yaml:"client_id"`
	ClientSecret string `yaml:"client_secret"`
	RedirectURL  string `yaml:"redirect_url"`
}

type ConfigJWT

type ConfigJWT struct {
	JWT JWTConfig `yaml:"jwt"`
}

ConfigJWT jwt config model

func (*ConfigJWT) Default

func (v *ConfigJWT) Default()

func (*ConfigJWT) Validate

func (v *ConfigJWT) Validate() error

type ConfigOAuth

type ConfigOAuth struct {
	Providers []Config `yaml:"oauth"`
}

ConfigOAuth oauth config model

func (*ConfigOAuth) Default

func (v *ConfigOAuth) Default()

type JWT

type JWT interface {
	GuardMiddleware() web.Middleware
	Sign(payload interface{}, ttl time.Duration) (string, error)
	SignCookie(ctx web.Context, payload interface{}, ttl time.Duration) error
}

type JWTConfig

type JWTConfig struct {
	Option JWTOption `yaml:"option"`
	Keys   []JWTKey  `yaml:"keys"`
}

type JWTHeader

type JWTHeader struct {
	Kid       string `json:"kid"`
	Alg       string `json:"alg"`
	IssuedAt  int64  `json:"iat"`
	ExpiresAt int64  `json:"eat"`
}

func (JWTHeader) MarshalEasyJSON

func (v JWTHeader) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (JWTHeader) MarshalJSON

func (v JWTHeader) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*JWTHeader) UnmarshalEasyJSON

func (v *JWTHeader) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*JWTHeader) UnmarshalJSON

func (v *JWTHeader) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type JWTKey

type JWTKey struct {
	ID        string `yaml:"id"`
	Key       string `yaml:"key"`
	Algorithm string `yaml:"alg"`
}

type JWTOption

type JWTOption struct {
	HeaderName bool   `yaml:"header_name"`
	CookieName string `yaml:"cookie_name"`
}

type OAuth

type OAuth interface {
	Request(code string) func(web.Context)
	Callback(code string, handler func(web.Context, OAuthUser, OAuthCode)) func(web.Context)
}

type OAuthCode

type OAuthCode string

type OAuthGoogleProvider

type OAuthGoogleProvider struct {
	// contains filtered or unexported fields
}

func (*OAuthGoogleProvider) AuthCodeKey

func (v *OAuthGoogleProvider) AuthCodeKey() string

func (*OAuthGoogleProvider) AuthCodeURL

func (v *OAuthGoogleProvider) AuthCodeURL() string

func (*OAuthGoogleProvider) Code

func (v *OAuthGoogleProvider) Code() string

func (*OAuthGoogleProvider) Config

func (v *OAuthGoogleProvider) Config(c Config)

func (*OAuthGoogleProvider) Exchange

func (v *OAuthGoogleProvider) Exchange(ctx context.Context, code string) (OAuthUser, error)

type OAuthOption

type OAuthOption interface {
	ApplyProvider(p ...OAuthProvider)
}

type OAuthProvider

type OAuthProvider interface {
	Code() string
	Config(conf Config)
	AuthCodeURL() string
	AuthCodeKey() string
	Exchange(ctx context.Context, code string) (OAuthUser, error)
}

type OAuthUser

type OAuthUser interface {
	GetName() string
	GetEmail() string
	GetIcon() string
}

type OAuthYandexProvider

type OAuthYandexProvider struct {
	// contains filtered or unexported fields
}

func (*OAuthYandexProvider) AuthCodeKey

func (v *OAuthYandexProvider) AuthCodeKey() string

func (*OAuthYandexProvider) AuthCodeURL

func (v *OAuthYandexProvider) AuthCodeURL() string

func (*OAuthYandexProvider) Code

func (v *OAuthYandexProvider) Code() string

func (*OAuthYandexProvider) Config

func (v *OAuthYandexProvider) Config(c Config)

func (*OAuthYandexProvider) Exchange

func (v *OAuthYandexProvider) Exchange(ctx context.Context, code string) (OAuthUser, error)

Jump to

Keyboard shortcuts

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