go_httpauth

package module
v0.0.0-...-9b2f6c0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2012 License: MIT Imports: 9 Imported by: 0

README

go_httpauth

modified from https://bitbucket.org/taruti/http_digest.go/

Interface to using server side http basic/digests authentication for golang.

example

basic_auth:
package main

import (
        "github.com/SunRunAway/go_httpauth"
        "net/http"
)

var s = go_httpauth.NewBasic("MyRealm",func(user string,realm string) string {
        // Replace this with a real lookup function here
    return "mypass"
})

func rootHandler(w http.ResponseWriter, r *http.Request) {
    if !s.Auth(w,r) { return }
    w.Write([]byte("<html><title>Hello</title><h1>Hello</h1></html>"))
}

func main() {
    http.HandleFunc("/", rootHandler)
    // In real life you'd use TLS with http Basic Auth
    http.ListenAndServe(":8080", nil)
}
degest_auth:
import (
    "github.com/SunRunAway/go_httpauth"
    "net/http"
)

var s = go_httpauth.NewDigest("MyRealm", func(user, realm string) string {
    // Replace this with a real lookup function here
    return go_httpauth.CalculateHA1(user, realm, "mypass")
})

func rootHandler(w http.ResponseWriter, r *http.Request) {
    if !s.Auth(w, r) {
        return
    }
    w.Write([]byte("<html><title>Hello</title><h1>Hello</h1></html>"))
}

func main() {
    http.HandleFunc("/", rootHandler)
    http.ListenAndServe(":8080", nil)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateHA1

func CalculateHA1(user, realm, pass string) string

Types

type BasicServer

type BasicServer Server

func NewBasic

func NewBasic(realm string, authfun func(user, realm string) string) *BasicServer

func (*BasicServer) Auth

Authenticates

type DigestServer

type DigestServer Server

func NewDigest

func NewDigest(realm string, authfun func(user, realm string) string) *DigestServer

func (*DigestServer) Auth

Authenticates

type Server

type Server struct {
	sync.Mutex
	AuthFun func(user, realm string) string

	Realm                             string
	ReaperWaitSeconds, ReapTTLSeconds int
	// contains filtered or unexported fields
}

func (*Server) Logout

func (s *Server) Logout(r *http.Request)

Jump to

Keyboard shortcuts

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