core

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: BSD-3-Clause Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMiddleware

func NewMiddleware(configFuncs ...ConfigFunc) middleware.Middleware

func RegisterProvider

func RegisterProvider(name ProviderName, provider Provider)

RegisterProvider registers Provider with ProviderName

Types

type ConfigFunc

type ConfigFunc func(c *config)

func AllowEmptyIdentity

func AllowEmptyIdentity() ConfigFunc

AllowEmptyIdentity allows unauthorized request to middleware

func UseCustomEmptyIdentityError

func UseCustomEmptyIdentityError(e *errors.Error) ConfigFunc

UseCustomEmptyIdentityError defines custom emptyIdentityError as e

func UseCustomEmptyIdentityErrorBuilder added in v0.0.2

func UseCustomEmptyIdentityErrorBuilder(f func(ctx context.Context) *errors.Error) ConfigFunc

UseCustomEmptyIdentityErrorBuilder defines custom emptyIdentityErrorBuilder as f

func UseProviders

func UseProviders(names []ProviderName) ConfigFunc

UseProviders defines Provider(s) that will be used in middleware as given ProviderName(s).

type Identity

type Identity struct {
	// ProviderName is name of authenticated Provider
	ProviderName ProviderName

	// Identifier is unique id of authenticated user/agent
	Identifier string

	// Extra is field for adding custom data
	Extra interface{}
}

Identity represents authenticated identity

func IdentityFromContext

func IdentityFromContext(ctx context.Context) Identity

IdentityFromContext returns Identity which stored in context.Context. NOTE: Identity can be empty depends on config. If you defined emptyIdentityError as nil, you must check emptiness with Identity.Empty()

func (*Identity) Empty

func (i *Identity) Empty() bool

Empty returns true if unauthenticated.

type Provider

type Provider interface {
	// Name returns registered ProviderName
	Name() ProviderName

	// Authenticate extracts Identity from server context and request
	// If you return non-nil error as second parameter, middleware will respond error directly.
	// Error must be errors.Error of kratos
	Authenticate(ctx context.Context, req interface{}) (*Identity, *errors.Error)
}

type ProviderName

type ProviderName string

ProviderName is unique name of provider

Jump to

Keyboard shortcuts

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