From 05ae3960da6b598850d7e2eb3d19870e951ca96d Mon Sep 17 00:00:00 2001 From: Lewis Watson Date: Tue, 21 Feb 2017 08:08:55 +0000 Subject: [PATCH] Add example usage to readme --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index 71735d4..ed96c10 100644 --- a/README.md +++ b/README.md @@ -9,3 +9,23 @@ This library follows the instructions described in [verify id tokens using third [Firebase]: https://firebase.google.com/ "Firebase" [JWT]: https://jwt.io/ "JWT" + +## Example Usage + +```go +import ( + "github.com/LewisWatson/firebase-jwt-auth" + "github.com/manyminds/api2go" +) + +// tokenVerifier previously initialsed with fireauth.New("projectname") +func verify(r api2go.Request, tokenVerifier fireauth.TokenVerifier) error { + token := r.Header.Get("authorization") + userID, claims, err := tokenVerifier.Verify(token) + if err != nil { + return err + } + r.Context.Set("userID", userID) + r.Context.Set("claims", claims) + return nil +}