auth

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2025 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

http basic / digect authentication to the Simplegoproxy server. Largely adopted from https://github.com/abbot/go-http-auth . See also: https://en.wikipedia.org/wiki/Digest_access_authentication .

Index

Constants

View Source
const (
	DefaultClientCacheSize      = 1000
	DefaultClientCacheTolerance = 100
)

Default values for ClientCacheSize and ClientCacheTolerance for DigestAuth

Variables

View Source
var NormalHeaders = &Headers{
	Authenticate:      "WWW-Authenticate",
	Authorization:     "Authorization",
	AuthInfo:          "Authentication-Info",
	UnauthCode:        http.StatusUnauthorized,
	UnauthContentType: "text/plain",
	UnauthResponse:    fmt.Sprintf("%d %s\n", http.StatusUnauthorized, http.StatusText(http.StatusUnauthorized)),
}

NormalHeaders are the regular Headers used by an HTTP Server for request authentication.

View Source
var ProxyHeaders = &Headers{
	Authenticate:      "Proxy-Authenticate",
	Authorization:     "Proxy-Authorization",
	AuthInfo:          "Proxy-Authentication-Info",
	UnauthCode:        http.StatusProxyAuthRequired,
	UnauthContentType: "text/plain",
	UnauthResponse:    fmt.Sprintf("%d %s\n", http.StatusProxyAuthRequired, http.StatusText(http.StatusProxyAuthRequired)),
}

ProxyHeaders are Headers used by an HTTP Proxy server for proxy access authentication.

Functions

func DigestAuthParams

func DigestAuthParams(authorization string) map[string]string

DigestAuthParams parses Authorization header from the http.Request. Returns a map of auth parameters or nil if the header is not a valid parsable Digest auth header.

func H

func H(data string) string

H function for MD5 algorithm (returns a lower-case hex MD5 digest)

func ParseList

func ParseList(value string) []string

ParseList parses a comma-separated list of values as described by RFC 2068 and returns list elements.

Lifted from https://code.google.com/p/gorilla/source/browse/http/parser/parser.go which was ported from urllib2.parse_http_list, from the Python standard library.

func ParsePairs

func ParsePairs(value string) map[string]string

ParsePairs extracts key/value pairs from a comma-separated list of values as described by RFC 2068 and returns a map[key]value. The resulting values are unquoted. If a list element doesn't contain a "=", the key is the element itself and the value is an empty string.

Lifted from https://code.google.com/p/gorilla/source/browse/http/parser/parser.go

Types

type Auth

type Auth struct {
	Realm            string
	Opaque           string
	PlainTextSecrets bool
	IgnoreNonceCount bool
	// Headers used by authenticator. Set to ProxyHeaders to use with
	// proxy server. When nil, NormalHeaders are used.
	Headers *Headers

	/*
	   Approximate size of Client's Cache. When actual number of
	   tracked client nonces exceeds
	   ClientCacheSize+ClientCacheTolerance, ClientCacheTolerance*2
	   older entries are purged.
	*/
	ClientCacheSize      int
	ClientCacheTolerance int
	// contains filtered or unexported fields
}

Auth is an authenticator implementation for 'Digest' HTTP Authentication scheme (RFC 7616).

Note: this implementation was written following now deprecated RFC 2617, and supports only MD5 algorithm.

TODO: Add support for SHA-256 and SHA-512/256 algorithms.

func NewAuthenticator

func NewAuthenticator(realm string, proxy bool) *Auth

NewAuthenticator generates a new DigestAuth object

func (*Auth) CheckAuth

func (a *Auth) CheckAuth(r *http.Request, username, password string, basic bool) (errres *http.Response, err error)

CheckAuth checks whether the request contains valid authentication data. If not, return a "RequireAuth" http response with an error.

func (*Auth) Purge

func (a *Auth) Purge(count int)

Purge removes count oldest entries from DigestAuth.clients

func (*Auth) Wrap

func (a *Auth) Wrap(wrapped http.HandlerFunc, user, pass string, basic bool) http.HandlerFunc

type Headers

type Headers struct {
	Authenticate      string // WWW-Authenticate
	Authorization     string // Authorization
	AuthInfo          string // Authentication-Info
	UnauthCode        int    // 401
	UnauthContentType string // text/plain
	UnauthResponse    string // Unauthorized.
}

Headers contains header and error codes used by authenticator.

Jump to

Keyboard shortcuts

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