Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BasicAuth ¶
func BasicAuth(o AuthOptions) func(http.Handler) http.Handler
BasicAuth provides HTTP middleware for protecting URIs with HTTP Basic Authentication as per RFC 2617. The server authenticates a user:password combination provided in the "Authorization" HTTP header.
Example:
package main import( "net/http" "github.com/zenazn/goji" "github.com/goji/httpauth" ) func main() { basicOpts := httpauth.AuthOptions{ Realm: "Restricted", User: "Dave", Password: "ClearText", } goji.Use(httpauth.BasicAuth(basicOpts), SomeOtherMiddleware) goji.Get("/thing", myHandler) }
Note: HTTP Basic Authentication credentials are sent in plain text, and therefore it does not make for a wholly secure authentication mechanism. You should serve your content over HTTPS to mitigate this, noting that "Basic Authentication" is meant to be just that: basic!
func SimpleBasicAuth ¶
SimpleBasicAuth is a convenience wrapper around BasicAuth. It takes a user and password, and returns a pre-configured BasicAuth handler using the "Restricted" realm and a default 401 handler.
Example:
package main import( "net/http" "github.com/zenazn/goji/web/httpauth" ) func main() { goji.Use(httpauth.SimpleBasicAuth("dave", "somepassword"), SomeOtherMiddleware) goji.Get("/thing", myHandler) }
Types ¶
type AuthOptions ¶
type AuthOptions struct { Realm string User string Password string AuthFunc func(string, string, *http.Request) bool }
AuthOptions stores the configuration for HTTP Basic Authentication.
A http.Handler may also be passed to UnauthorizedHandler to override the default error handler if you wish to serve a custom template/response.