auth

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppFromContext

func AppFromContext(ctx context.Context) (string, string)

AppFromContext get app from context

func LoginFromContext

func LoginFromContext(ctx context.Context) (string, string)

LoginFromContext get login from context

func StreamServerInterceptor

func StreamServerInterceptor(authorize Authorize) grpc.StreamServerInterceptor

StreamServerInterceptor returns a new unary server interceptors that performs per-request auth.

func TokenFromContext

func TokenFromContext(ctx context.Context) string

TokenFromContext get token from context

func UnaryServerInterceptor

func UnaryServerInterceptor(authorize Authorize) grpc.UnaryServerInterceptor

UnaryServerInterceptor returns a new unary server interceptors that performs per-request auth.

Types

type AppCredential

type AppCredential struct {
	RequireTLS bool
	Key        string
	Secret     string
}

AppCredential authorize via appkey and appsecret

func (AppCredential) GetRequestMetadata

func (c AppCredential) GetRequestMetadata(context.Context, ...string) (map[string]string, error)

GetRequestMetadata build app metadata

func (AppCredential) RequireTransportSecurity

func (c AppCredential) RequireTransportSecurity() bool

RequireTransportSecurity indicates whether the credentials requires transport security.

type Authorize

type Authorize func(ctx context.Context) (context.Context, error)

Authorize is the pluggable function that performs authentication.

type Authorizer

type Authorizer interface {
	Authorize(ctx context.Context, fullMethodName string) (context.Context, error)
}

Authorizer allows a given gRPC service implementation to override the global `Authorize`.

If a service implements the AuthorizeOverride method, it takes precedence over the `Authorize` method, and will be called instead of Authorize for all method invocations within that service.

type LoginCredential

type LoginCredential struct {
	RequireTLS bool
	Login      string
	Passwd     string
}

LoginCredential authorize via login and password

func (*LoginCredential) GetRequestMetadata

func (c *LoginCredential) GetRequestMetadata(context.Context, ...string) (map[string]string, error)

GetRequestMetadata build login metadata

func (*LoginCredential) RequireTransportSecurity

func (c *LoginCredential) RequireTransportSecurity() bool

RequireTransportSecurity indicates whether the credentials requires transport security.

type Metadata

type Metadata metadata.MD

Metadata is a convenience wrapper definiting extra functions on the metadata.

func FromIncoming

func FromIncoming(ctx context.Context) Metadata

FromIncoming extracts an inbound metadata from the server-side context.

This function always returns a Metadata wrapper of the metadata.MD, in case the context doesn't have metadata it returns a new empty Metadata.

func FromOutgoing

func FromOutgoing(ctx context.Context) Metadata

FromOutgoing extracts an outbound metadata from the client-side context.

This function always returns a Metadata wrapper of the metadata.MD, in case the context doesn't have metadata it returns a new empty Metadata.

func (Metadata) Add

func (m Metadata) Add(key string, value string) Metadata

Add retrieves a single value from the metadata.

It works analogously to http.Header.Add, as it appends to any existing values associated with key.

func (Metadata) AsMD

func (m Metadata) AsMD() *metadata.MD

func (Metadata) Del

func (m Metadata) Del(key string) Metadata

Del retrieves a single value from the metadata.

It works analogously to http.Header.Del, deleting all values if they exist.

func (Metadata) FirstValue

func (m Metadata) FirstValue(key string, defalutValue string) string

FirstValue retrieves a single value from the metadata.

It works analogously to http.Header.Get, returning the first value if there are many set. If the value is not set, an empty string is returned.

func (Metadata) LastValue

func (m Metadata) LastValue(key string, defalutValue string) string

LastValue retrieves a single value from the metadata.

func (Metadata) Set

func (m Metadata) Set(key string, value string) Metadata

Set sets the given value in a metadata.

It works analogously to http.Header.Set, overwriting all previous metadata values.

func (Metadata) ToIncoming

func (m Metadata) ToIncoming(ctx context.Context) context.Context

ToIncoming sets the given Metadata as a server-side context for dispatching.

This is mostly useful in ServerInterceptors..

func (Metadata) ToOutgoing

func (m Metadata) ToOutgoing(ctx context.Context) context.Context

ToOutgoing sets the given Metadata as a client-side context for dispatching.

func (Metadata) Values

func (m Metadata) Values(key string) []string

Values retrieves all values from the metadata.

type ServerStream

type ServerStream struct {
	grpc.ServerStream
	// WrappedContext is the wrapper's own Context. You can assign it.
	WrappedContext context.Context
}

ServerStream is a thin wrapper around grpc.ServerStream that allows modifying context.

func WrapServerStream

func WrapServerStream(stream grpc.ServerStream) *ServerStream

WrapServerStream returns a ServerStream that has the ability to overwrite context.

func (*ServerStream) Context

func (w *ServerStream) Context() context.Context

Context returns the wrapper's WrappedContext, overwriting the nested grpc.ServerStream.Context()

type TokenCredential

type TokenCredential struct {
	RequireTLS bool
	Token      string
}

TokenCredential authorize via token

func (TokenCredential) GetRequestMetadata

func (c TokenCredential) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error)

GetRequestMetadata build token metadata

func (TokenCredential) RequireTransportSecurity

func (c TokenCredential) RequireTransportSecurity() bool

RequireTransportSecurity indicates whether the credentials requires transport security.

Jump to

Keyboard shortcuts

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