https://github.com/k-phoen/http-auth
[DEPRECATED] HTTP Authentication middleware
https://github.com/k-phoen/http-auth
Last synced: 6 months ago
JSON representation
[DEPRECATED] HTTP Authentication middleware
- Host: GitHub
- URL: https://github.com/k-phoen/http-auth
- Owner: K-Phoen
- License: mit
- Created: 2014-11-09T10:54:04.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2016-05-29T19:09:37.000Z (over 9 years ago)
- Last Synced: 2024-05-01T20:12:59.149Z (over 1 year ago)
- Language: Go
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
http-auth
=========Authentication HTTP middleware for Go applications.
## Status
This project is **DEPRECATED** and should NOT be used.
If someone magically appears and wants to maintain this project, I'll gladly give access to this repository.
## Usage
Here is a ready to use example with [Negroni](https://github.com/codegangsta/negroni):
```go
package mainimport (
"fmt"
"net/http""github.com/codegangsta/negroni"
"github.com/K-Phoen/http-negotiate/negotiate"
)func main() {
mux := http.NewServeMux()mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
fmt.Fprintf(w, "Welcome to the home page!")
fmt.Fprintf(w, "The negotiated format is: " + w.Header().Get("Content-Type"))
})authOptions := &AuthOptions{
Realm: "Restricted",
AuthenticationMethod: func(login, password string) bool {
return auth.SecureCompare(login, "test") && auth.SecureCompare(password, "tata")
},
}n := negroni.Classic()
n.UseHandler(BasicAuth(authOptions))
n.UseHandler(mux)
n.Run(":3000")
}
```Or without [Negroni](https://github.com/codegangsta/negroni) and only for one
handler:```go
package mainimport (
"github.com/K-Phoen/http-auth/auth"
"log"
"net/http"
)func hello_action(w http.ResponseWriter, req *http.Request) {
w.Write([]byte("Hello!"))
}func main() {
mux := http.NewServeMux()basicAuth := auth.BasicAuth(&auth.AuthOptions{
Realm: "Restricted",
AuthenticationMethod: func(login, password string) bool {
return auth.SecureCompare(login, "test") && auth.SecureCompare(password, "tata")
},
})mux.Handle("/hello", basicAuth.Wrap(hello_action))
log.Println("Listening...")
http.ListenAndServe(":3000", mux)
}
```## ToDo
* write tests
* implement other authentication types## License
This library is released under the MIT License. See the bundled LICENSE file for
details.