Documentation
¶
Overview ¶
Package microauth provides a uniform means of serving HTTP/S for golang projects securely. It allows the specification of a certificate (or generates one) as well as an auth token which is checked before the request is processed.
Index ¶
- Variables
- func Generate(host string) (*tls.Certificate, error)
- func ListenAndServe(addr, token string, h http.Handler, excludedPaths ...string) error
- func ListenAndServeTLS(addr, token string, h http.Handler, excludedPaths ...string) error
- func Load(certFile, keyFile, password string) (*tls.Certificate, error)
- type Auth
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // DefaultAuth is the default Auth object DefaultAuth = &Auth{} )
Functions ¶
func Generate ¶
func Generate(host string) (*tls.Certificate, error)
Generate is a helper function which generates a tls.Certificate for serving TLS requests.
func ListenAndServe ¶
ListenAndServe is a shortcut function which uses the default one
Example ¶
package main
import (
"io"
"net/http"
microauth "github.com/mu-box/golang-microauth"
)
func main() {
http.HandleFunc("/", func(rw http.ResponseWriter, req *http.Request) {
io.WriteString(rw, "World, Hello!\n")
})
microauth.ListenAndServe("127.0.0.1:80", "secret", nil)
}
func ListenAndServeTLS ¶
ListenAndServeTLS is a shortcut function which uses the default one
Example ¶
package main
import (
"io"
"net/http"
microauth "github.com/mu-box/golang-microauth"
)
func main() {
http.HandleFunc("/", func(rw http.ResponseWriter, req *http.Request) {
io.WriteString(rw, "World, Hello!\n")
})
cert, _ := microauth.Generate("microauth.microbox.cloud")
microauth.DefaultAuth.Header = "X-AUTH-TOKEN"
microauth.DefaultAuth.Certificate = cert
microauth.ListenAndServeTLS("127.0.0.1:443", "secret", nil)
}
Types ¶
type Auth ¶
type Auth struct {
Header string // Header is the authentication token's header name
Certificate *tls.Certificate // Certificate is the tls.Certificate to serve requests with
ExcludedPaths []string // ExcludedPaths is a list of paths to be excluded from being authenticated
Token string // Token is the security/authentication string to validate by
// contains filtered or unexported fields
}
Auth is a structure containing listener information
func (*Auth) ListenAndServe ¶
ListenAndServe starts a normal tcp listener and handles serving http while still validating the auth token.
Click to show internal directories.
Click to hide internal directories.