auth

package
v0.0.0-...-dcd54df Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2020 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// AllValidClaims is a list of the claims expected from a JWT token
	AllValidClaims = []string{
		apiProductListClaim, audienceClaim, clientIDClaim, applicationNameClaim,
		scopesClaim, expClaim, developerEmailClaim,
	}
)
View Source
var ErrBadAuth = errors.New("permission denied")

ErrBadAuth is an error because of incorrect auth

View Source
var ErrInternalError = errors.New("internal error")

ErrInternalError is an error because of internal error

View Source
var ErrNoAuth = errors.New("missing authentication")

ErrNoAuth is an error because of missing auth

Functions

This section is empty.

Types

type APIKeyRequest

type APIKeyRequest struct {
	APIKey string `json:"apiKey"`
}

APIKeyRequest is the request to Apigee's verifyAPIKey API

type APIKeyResponse

type APIKeyResponse struct {
	Token string `json:"token"`
}

APIKeyResponse is the response from Apigee's verifyAPIKey API

type Context

type Context struct {
	context.Context
	ClientID       string
	AccessToken    string
	Application    string
	APIProducts    []string
	Expires        time.Time
	DeveloperEmail string
	Scopes         []string
	APIKey         string
}

A Context wraps all the various information that is needed to make requests through the Apigee adapter.

type Manager

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

An Manager handles all things related to authentication.

func NewManager

func NewManager(env adapter.Env, options Options) (*Manager, error)

NewManager constructs a new Manager and begins an update loop to periodically refresh JWT credentials if options.pollInterval > 0. Call Close() when done.

func (*Manager) Authenticate

func (m *Manager) Authenticate(ctx context.Context, apiKey string,
	claims map[string]interface{}, apiKeyClaimKey string) (*Context, error)

Authenticate constructs an Apigee context from an existing context and either a set of JWT claims, or an Apigee API key. The following logic applies: 1. If JWT w/ API Key - use API Key in claims 2. API Key - use API Key 3. Has JWT token - use JWT claims If any method is provided but fails, the next available one(s) will be attempted. If all provided methods fail, the request will be rejected.

func (*Manager) Close

func (m *Manager) Close()

Close shuts down the Manager.

type Options

type Options struct {
	// PollInterval sets refresh rate of JWT credentials, disabled if = 0
	PollInterval time.Duration
	// Client is a configured HTTPClient
	Client *http.Client
	// APIKeyCacheDuration is the length of time APIKeys are cached when unable to refresh
	APIKeyCacheDuration time.Duration
}

Options allows us to specify options for how this auth manager will run

Jump to

Keyboard shortcuts

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