diff --git a/README.md b/README.md index baab52f..535a154 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ your application: package main import ( + "encoding/json" "errors" "fmt" "net/http" @@ -41,8 +42,16 @@ func setClaims(id string) (map[string]interface{}, error) { }, nil } -func verifyClaims([]byte) error { - // We don't really care about the claims, just approve as-is +func verifyClaims(claims []byte) error { + currentTime := time.Now() + var c struct { + Iat int64 + Exp int64 + } + _ = json.Unmarshal(claims, &c) + if currentTime.After(time.Unix(c.Exp, 0)) { + return errors.New("this token has expired") + } return nil } diff --git a/examples/net-http.go b/examples/net-http.go index 7910dbe..51a14d1 100644 --- a/examples/net-http.go +++ b/examples/net-http.go @@ -1,6 +1,7 @@ package main import ( + "encoding/json" "errors" "fmt" "net/http" @@ -33,8 +34,16 @@ func setClaims(id string) (map[string]interface{}, error) { }, nil } -func verifyClaims([]byte) error { - // We don't really care about the claims, just approve as-is +func verifyClaims(claims []byte) error { + currentTime := time.Now() + var c struct { + Iat int64 + Exp int64 + } + _ = json.Unmarshal(claims, &c) + if currentTime.After(time.Unix(c.Exp, 0)) { + return errors.New("this token has expired") + } return nil }