auth

package
v0.0.0-...-4b6c1ef Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	ESPV2_USER_INFO_HEADER = "x-endpoint-api-userinfo"
)

Variables

View Source
var (
	ErrTokenSource = errors.New("missing token source in context")
	ErrUserInfo    = errors.New("missing user info in context")
	ErrNoSourceIP  = errors.New("missing sourceip in context")
)

Functions

func SourceIPAuth

func SourceIPAuth(ctx context.Context) (context.Context, error)

SourceIPAuth implements github.com/grpc-ecosystem/go-grpc-middleware/auth.AuthFunc and determines the source IP address of the caller in the following order:

  • First entry in x-forwarded-for header if present
  • Fallback to gRPC peer IP address

func SourceIPFrom

func SourceIPFrom(ctx context.Context) (net.IP, error)

func TokenSourceFrom

func TokenSourceFrom(ctx context.Context) (oauth2.TokenSource, error)

func UserInfoFrom

func UserInfoFrom(ctx context.Context) (*oidc.UserInfo, error)

func WithSourceIP

func WithSourceIP(ctx context.Context, ip net.IP) context.Context

func WithTokenSource

func WithTokenSource(ctx context.Context, ts oauth2.TokenSource) context.Context

func WithUserInfo

func WithUserInfo(ctx context.Context, ui *oidc.UserInfo) context.Context

Types

type ESPv2Auth

type ESPv2Auth struct {
}

ESPv2Auth can be used by github.com/grpc-ecosystem/go-grpc-middleware/auth extracting the user info from gRPC metadata. No validation needs to be performed since ESPv2 already validated the token for us. Do not use this for deployments without a front-facing ESPv2 deployment.

func (*ESPv2Auth) AuthFunc

func (a *ESPv2Auth) AuthFunc(ctx context.Context) (context.Context, error)

AuthFunc implments github.com/grpc-ecosystem/go-grpc-middleware/auth.AuthFunc

type IDToken

type IDToken struct {
	Insecure bool
}

IDToken immplements github.com/grpc/grpc-go/credentials.PerRPCCredentials. It loads the TokenSource from context and uses its id_token as a bearer.

func (*IDToken) GetRequestMetadata

func (i *IDToken) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error)

GetRequestMetadata immplements credentials.PerRPCCredentials.

func (*IDToken) RequireTransportSecurity

func (i *IDToken) RequireTransportSecurity() bool

RequireTransportSecurity immplements credentials.PerRPCCredentials.

Jump to

Keyboard shortcuts

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