auth

package
v0.2.13 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultBasicAuthConfig is the default BasicAuth middleware config.
	DefaultBasicAuthConfig = BasicAuthConfig{
		Realm: defaultRealm,
	}
)
View Source
var (
	// DefaultKeyAuthConfig is the default KeyAuth middleware config.
	DefaultKeyAuthConfig = KeyAuthConfig{
		KeyLookup:  "header:" + cnst.HeaderAuthorization,
		AuthScheme: "Bearer",
	}
)

Functions

func BasicAuth

func BasicAuth(fn BasicAuthValidator) gin.HandlerFunc

BasicAuth returns an BasicAuth middleware.

For valid credentials it calls the next handler. For missing or invalid credentials, it sends "401 - Unauthorized" response.

func BasicAuthWithConfig

func BasicAuthWithConfig(config BasicAuthConfig) gin.HandlerFunc

BasicAuthWithConfig returns an BasicAuth middleware with config. See `BasicAuth()`.

func KeyAuth

func KeyAuth(fn KeyAuthValidator) gin.HandlerFunc

KeyAuth returns an KeyAuth middleware.

For valid key it calls the next handler. For invalid key, it sends "401 - Unauthorized" response. For missing key, it sends "400 - Bad Request" response.

func KeyAuthWithConfig

func KeyAuthWithConfig(config KeyAuthConfig) gin.HandlerFunc

KeyAuthWithConfig returns an KeyAuth middleware with config. See `KeyAuth()`.

func SetUp

func SetUp() gin.HandlerFunc

Types

type BasicAuthConfig

type BasicAuthConfig struct {
	// Validator is a function to validate BasicAuth credentials.
	// Required.
	Validator BasicAuthValidator

	// Realm is a string to define realm attribute of BasicAuth.
	// Default value "Restricted".
	Realm string
}

BasicAuthConfig defines the config for BasicAuth middleware.

type BasicAuthValidator

type BasicAuthValidator func(string, string, gin.Context) (bool, error)

BasicAuthValidator defines a function to validate BasicAuth credentials.

type KeyAuthConfig

type KeyAuthConfig struct {
	// KeyLookup is a string in the form of "<source>:<name>" that is used
	// to extract key from the request.
	// Optional. Default value "header:Authorization".
	// Possible values:
	// - "header:<name>"
	// - "query:<name>"
	// - "form:<name>"
	KeyLookup string `yaml:"key_lookup"`

	// AuthScheme to be used in the Authorization header.
	// Optional. Default value "Bearer".
	AuthScheme string

	// Validator is a function to validate key.
	// Required.
	Validator KeyAuthValidator
}

KeyAuthConfig defines the config for KeyAuth middleware.

type KeyAuthValidator

type KeyAuthValidator func(string, gin.Context) (bool, error)

KeyAuthValidator defines a function to validate KeyAuth credentials.

Jump to

Keyboard shortcuts

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