Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( MissingDateParam = errors.New("missing date param") InvalidEscherKey = errors.New("Invalid Escher key") AlgorithmNotAllowed = errors.New("Only SHA256 and SHA512 hash algorithms are allowed") RequestMethodIsInvalid = errors.New("The request method is invalid") POSTRequestBodyIsEmpty = errors.New("The request body shouldn't be empty if the request method is POST") CredentialDateNotMatching = errors.New("The credential date does not match with the request date") RequestDateNotAcceptable = errors.New("The request date is not within the accepted time range") AuthorizationDateIsInvalid = errors.New("Invalid date in authorization header, it should equal with date header") InvalidCredentialScope = errors.New("The credential scope is invalid") HostHeaderNotSigned = errors.New("The host header is not signed") DateHeaderIsNotSigned = errors.New("The date header is not signed") SignatureDoesNotMatch = errors.New("The signatures do not match") MalformedAuthHeader = errors.New("Could not parse auth header") SigningParamNotFound = errors.New("Signing Param not found") SchemaInURLNotAllowed = errors.New("The request url shouldn't contains http or https") HTTPSchemaFoundInTheURL = errors.New("The request url shouldn't contains http or https") )
Functions ¶
This section is empty.
Types ¶
type Validator ¶
Example ¶
package main import ( "fmt" "log" "net/http" "github.com/EscherAuth/escher/config" "github.com/EscherAuth/escher/keydb" "github.com/EscherAuth/escher/request" "github.com/EscherAuth/escher/validator" ) func main() { Config, err := config.NewFromENV() if err != nil { log.Fatal(err) } keyDB, err := keydb.NewFromENV() if err != nil { log.Fatal(err) } Validator := validator.New(Config) handler := func(w http.ResponseWriter, r *http.Request) { escherRequest, err := request.NewFromHTTPRequest(r) if err != nil { log.Println(err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } apiKey, err := Validator.Validate(escherRequest, keyDB, nil) if err != nil { w.Header().Set("WWW-Authenticate", "EscherAuth") http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized) return } log.Printf("request received from: %v\n", apiKey) w.Header().Set("Content-Type", "text/plain; charset=utf-8") w.WriteHeader(200) fmt.Fprintln(w, "OK") } mux := http.NewServeMux() mux.HandleFunc("/", handler) err = http.ListenAndServe(":9292", mux) if err != nil { log.Fatal(err) } }
Output:
Click to show internal directories.
Click to hide internal directories.