httpauth

package module
v0.0.0-...-879c9c8 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2015 License: MIT Imports: 9 Imported by: 0

README

httpauth GoDoc

httpauth currently provides HTTP Basic Authentication middleware for kami.

It is a quick and dirty fork of goji/httpauth.

Documentation

Overview

Basic http auth for kami

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BasicAuth

func BasicAuth(o AuthOptions) kami.Middleware

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/zenazn/goji/web/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

func SimpleBasicAuth(user, password string) kami.Middleware

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
	UnauthorizedHandler func(ctx context.Context, w http.ResponseWriter, r *http.Request)
}

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.

Jump to

Keyboard shortcuts

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