MCPcopy Index your code
hub / github.com/abbot/go-http-auth

github.com/abbot/go-http-auth @v0.4.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.4.0 ↗ · + Follow
79 symbols 170 edges 15 files 33 documented · 42% 15 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

HTTP Authentication implementation in Go

This is an implementation of HTTP Basic and HTTP Digest authentication in Go language. It is designed as a simple wrapper for http.RequestHandler functions.

Features

  • Supports HTTP Basic and HTTP Digest authentication.
  • Supports htpasswd and htdigest formatted files.
  • Automatic reloading of password files.
  • Pluggable interface for user/password storage.
  • Supports MD5, SHA1 and BCrypt for Basic authentication password storage.
  • Configurable Digest nonce cache size with expiration.
  • Wrapper for legacy http handlers (http.HandlerFunc interface)

Example usage

This is a complete working example for Basic auth:

package main

import (
        "fmt"
        "net/http"

        auth "github.com/abbot/go-http-auth"
)

func Secret(user, realm string) string {
        if user == "john" {
                // password is "hello"
                return "$1$dlPL2MqE$oQmn16q49SqdmhenQuNgs1"
        }
        return ""
}

func handle(w http.ResponseWriter, r *auth.AuthenticatedRequest) {
        fmt.Fprintf(w, "<html><body><h1>Hello, %s!</h1></body></html>", r.Username)
}

func main() {
        authenticator := auth.NewBasicAuthenticator("example.com", Secret)
        http.HandleFunc("/", authenticator.Wrap(handle))
        http.ListenAndServe(":8080", nil)
}

See more examples in the "examples" directory.

Legal

This module is developed under Apache 2.0 license, and can be used for open and proprietary projects.

Copyright 2012-2013 Lev Shamardin

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file or any other part of this project except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Extension points exported contracts — how you extend this code

SecretProvider (FuncType)
* SecretProvider is used by authenticators. Takes user name and realm as an argument, returns secret required for auth
users.go
AuthenticatedHandlerFunc (FuncType)
* AuthenticatedHandlerFunc is like http.HandlerFunc, but takes AuthenticatedRequest instead of http.Request */
auth.go
ContextHandler (Interface)
(no doc)
examples/context.go
Authenticator (FuncType)
* Authenticator wraps an AuthenticatedHandlerFunc with authentication-checking code. Typical Authenticator usage is
auth.go
ContextHandlerFunc (FuncType)
(no doc)
examples/context.go
AuthenticatorInterface (Interface)
(no doc) [2 implementers]
auth.go

Core symbols most depended-on inside this repo

V
called by 14
misc.go
CheckAuth
called by 11
digest.go
CheckAuth
called by 6
basic.go
H
called by 6
misc.go
HtpasswdFileProvider
called by 3
users.go
Wrap
called by 3
auth.go
RandomKey
called by 3
misc.go
ReloadIfNeeded
called by 2
users.go

Shape

Function 39
Method 20
Struct 11
FuncType 5
Interface 2
TypeAlias 2

Languages

Go100%

Modules by API surface

digest.go15 symbols
auth.go11 symbols
users.go9 symbols
basic.go9 symbols
examples/context.go8 symbols
misc.go6 symbols
users_test.go3 symbols
md5crypt.go3 symbols
examples/wrapped.go3 symbols
examples/digest.go3 symbols
examples/basic.go3 symbols
misc_test.go2 symbols

For agents

$ claude mcp add go-http-auth \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact