Need help with go-http-auth?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

abbot
496 Stars 109 Forks Apache License 2.0 81 Commits 13 Opened issues

Description

Basic and Digest HTTP Authentication for golang http

Services available

!
?

Need anything else?

Contributors list

# 106,137
Go
Shell
protoco...
protobu...
53 commits
# 161,496
Shell
Go
backoff
golang
3 commits
# 28,100
Go
seleniu...
c-sharp
hub
1 commit
# 9,661
gRPC
Perl
x11-wm
hlsl
1 commit
# 377,048
kde
xfce
Unity
k8s
1 commit
# 100,882
Twitch
hlsl
glsl
gmail
1 commit
# 28,790
C
sed
hugo
prometh...
1 commit
# 77,283
es6-jav...
Go
HTML
Shell
1 commit
# 34,251
XML
pooling
vuejs
bitbuck...
1 commit
# 17,590
Go
golang
Sublime...
struct
1 commit
# 406,029
PHP
Symfony
Go
traefik
1 commit

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, "

Hello, %s!

", 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.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.