Documentation ¶
Index ¶
- Variables
- func Handle(auth Authorizer, fn func(http.ResponseWriter, *http.Request)) http.Handler
- func HandlerFunc(auth Authorizer, fn func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request)
- func Middleware(auth Authorizer) func(http.Handler) http.Handler
- type Authorizer
- type Digest
- type Realm
- type User
Constants ¶
This section is empty.
Variables ¶
var ContextKey = contextKey("Identity")
ContextKey is the key used to store the identity from an IsAuthorized call into a request's context.Context. This is used for middleware and handlers.
Functions ¶
func Handle ¶
func Handle( auth Authorizer, fn func(http.ResponseWriter, *http.Request), ) http.Handler
Handle can be used with some web frameworks for creating authorization middleware. If a request fails to pass authorization, the authorizer's failure handler is used generate a response, and the request is no longer processed.
func HandlerFunc ¶
func HandlerFunc( auth Authorizer, fn func(http.ResponseWriter, *http.Request), ) func(http.ResponseWriter, *http.Request)
HandlerFunc can be used with some web frameworks for creating authorization middleware. If a request fails to pass authorization, the authorizer's failure handler is used generate a response, and the request is no longer processed.
func Middleware ¶
func Middleware(auth Authorizer) func(http.Handler) http.Handler
Middleware can be used with some web frameworks for creating authorization middleware. If a request fails to pass authorization, the authorizer's failure handler is used generate a response, and the request is no longer processed.
Types ¶
type Authorizer ¶
type Authorizer interface { IsAuthorized(*http.Request) (string, error) FailureHandler(error) http.Handler }
Authorizer specifies an interface which enables performing authentication checks and providing an HTTP failure handler.
type Digest ¶
type Digest struct {
// contains filtered or unexported fields
}
Digest represents a new HTTP Digest Authentication manager.
func MakeDigest ¶
MakeDigest returns an instantiated Digest instance. Specify how many times a nonce can be used, and how long it will last. Expired nonces will be cleaned up automatically.
func (Digest) FailureHandler ¶
FailureHandler reponds with a 401 HTTP code, the WWW-Authenticate header, and an error message for HTTP Basic Auth failed requests.
type Realm ¶
Realm represents a collection of Users for a given HTTP Basic Auth realm.
func MakeRealm ¶
MakeRealm creates a new Realm instance for the given realm string and any applicable Users. This will default the Realm's charset is utf-8. If no users are provided, or users share the same username, an error will occur.
func (Realm) FailureHandler ¶
FailureHandler reponds with a 401 HTTP code, the WWW-Authenticate header, and an error message for HTTP Basic Auth failed requests.
type User ¶
type User struct {
// contains filtered or unexported fields
}
User represents a single HTTP Basic Auth username and password pair. Since the username and password of a User are non-exported, you should create a new User using MakeUser(username, password).
func MakeUser ¶
MakeUser creates a new User instance with the specified username and plaintext password. Usernames containing any colon characters results in a panic.
func (User) FailureHandler ¶
FailureHandler reponds with a 401 HTTP code, the WWW-Authenticate header, and an error message for HTTP Basic Auth failed requests. The realm is set as Restricted with the character set of utf-8. To control these, use a Realm instead.