auth

package
v0.0.0-...-785fa05 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2018 License: MIT Imports: 7 Imported by: 0

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/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 ParseCredentials

func ParseCredentials(r *http.Request) (creds [][]byte, ok bool)

func SimpleBasicAuth

func SimpleBasicAuth(user, password string) func(http.Handler) http.Handler

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(username string, password string) bool
	UnauthorizedHandler http.Handler
}

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.

Either supply a User+Password or an AuthFunc.

Jump to

Keyboard shortcuts

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