auth

package
v1.7.10 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	UserIdXAuthKey   = "auth_user_id"
	AccessesXAuthKey = "accesses_user_id"
)

Functions

func InitWithOptions

func InitWithOptions(options ...Options)

func NMiddleware

func NMiddleware(store PublicKeyStore) func(c *gin.Context)

func WithMaxAccessTokenAge

func WithMaxAccessTokenAge(maxAge time.Duration) func(c *Config)

func WithMaxRefreshTokenAge

func WithMaxRefreshTokenAge(maxAge time.Duration) func(c *Config)

func ZHandler

func ZHandler(accesses []Access) gin.HandlerFunc

ZHandler is a gin middleware creator that checks if the user has the required access. ZHandler is similar to ZMiddleware, but it is used to check the access of a single API.

func ZMiddleware

func ZMiddleware(accessMap map[string][]Access) gin.HandlerFunc

ZMiddleware is a gin middleware creator that checks if the user has the required access. ZMiddleware is similar to ZHandler, but it is used to check the access of multiple APIs and supports path matching.

Types

type Access

type Access string

type AccessTokenClaims

type AccessTokenClaims struct {
	ExpirableClaims
	Account  string      `json:"sub"`
	UserId   interface{} `json:"uid"`
	Audience string      `json:"aud,omitempty"`
	Issuer   string      `json:"iss,omitempty"`
	Accesses []Access    `json:"accesses,omitempty"`
}

type Config

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

func NewConfig

func NewConfig(options ...Options) *Config

type DataSource

type DataSource interface {
	FetchUser(ctx context.Context, userAccount string) User
}

type ExpirableClaims

type ExpirableClaims struct {
	ExpiresAt int64 `json:"exp,omitempty"`
}

func (*ExpirableClaims) Valid

func (t *ExpirableClaims) Valid() error

func (*ExpirableClaims) VerifyExpiresAt

func (t *ExpirableClaims) VerifyExpiresAt(cmp int64) bool

type KeyInfo

type KeyInfo struct {
	Key      *ecdsa.PublicKey
	ExpireAt time.Time
	KeyId    string
}

type NEndpointOptions

type NEndpointOptions struct {
	MaxKeyAge time.Duration
}

func NewNEndpointOptions

func NewNEndpointOptions() *NEndpointOptions

type NEndpoints

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

func NewNEndpoints

func NewNEndpoints(ctx context.Context, keystore PublicKeyStore, authDs DataSource, options *NEndpointOptions) *NEndpoints

func (*NEndpoints) LoginEndpoint

func (n *NEndpoints) LoginEndpoint(c *gin.Context)

func (*NEndpoints) RefreshKey

func (n *NEndpoints) RefreshKey(ctx context.Context)

func (*NEndpoints) RefreshTokenEndpoint

func (n *NEndpoints) RefreshTokenEndpoint(c *gin.Context)

type NRefreshRequest

type NRefreshRequest struct {
	RefreshToken string `form:"refresh_token" json:"refresh_token"`
}

type NRequest

type NRequest struct {
	Account  string `form:"account"`
	Password string `form:"password"`
}

type NResponse

type NResponse struct {
	AccessToken     string `json:"access_token"`
	RefreshToken    string `json:"refresh_token"`
	ExpireAt        int64  `json:"expire_at"`
	RefreshExpireAt int64  `json:"refresh_expire_at"`
}

type Options

type Options func(c *Config)

type PublicKeyStore

type PublicKeyStore interface {
	SavePublicKey(ctx context.Context, info *KeyInfo) error
	LoadPublicKey(ctx context.Context, keyId string) *ecdsa.PublicKey
}

type RefreshTokenClaims

type RefreshTokenClaims struct {
	ExpirableClaims
	UserId  interface{} `json:"uid"`
	Account string      `json:"sub"`
}

type User

type User interface {
	VerifyPassword(password string) bool
	Id() interface{}
	Name() string
	Account() string
	Accesses() []Access
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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