diff options
Diffstat (limited to 'cmd/ponzu/vendor/github.com/nilslice/jwt/README.md')
m--------- | cmd/ponzu/vendor/github.com/nilslice/jwt | 0 | ||||
-rw-r--r-- | cmd/ponzu/vendor/github.com/nilslice/jwt/README.md | 43 |
2 files changed, 43 insertions, 0 deletions
diff --git a/cmd/ponzu/vendor/github.com/nilslice/jwt b/cmd/ponzu/vendor/github.com/nilslice/jwt deleted file mode 160000 -Subproject dab3054ad0d56718877715dc429b95302cf4c7d diff --git a/cmd/ponzu/vendor/github.com/nilslice/jwt/README.md b/cmd/ponzu/vendor/github.com/nilslice/jwt/README.md new file mode 100644 index 0000000..a384dd1 --- /dev/null +++ b/cmd/ponzu/vendor/github.com/nilslice/jwt/README.md @@ -0,0 +1,43 @@ +# JWT + +### Usage + $ go get github.com/nilslice/jwt + +package jwt provides methods to create and check JSON Web Tokens. It only implements HMAC 256 encryption and has a very small footprint, ideal for simple usage when authorizing clients + +```go + package main + + import ( + auth "github.com/nilslice/jwt" + "fmt" + "net/http" + "strings" + ) + + func main() { + http.HandleFunc("/auth/new", func(res http.ResponseWriter, req *http.Request) { + claims := map[string]interface{}{"exp": time.Now().Add(time.Hour * 24).Unix()} + token, err := auth.New(claims) + if err != nil { + http.Error(res, "Error", 500) + return + } + res.Header().Add("Authorization", "Bearer "+token) + + res.WriteHeader(http.StatusOK) + }) + + http.HandleFunc("/auth", func(res http.ResponseWriter, req *http.Request) { + userToken := strings.Split(req.Header.Get("Authorization"), " ")[1] + + if auth.Passes(userToken) { + fmt.Println("ok") + } else { + fmt.Println("no") + } + }) + + http.ListenAndServe(":8080", nil) + } +``` |