forked from dgrijalva/jwt-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package jwt_test | ||
|
||
import ( | ||
"fmt" | ||
"github.com/dgrijalva/jwt-go" | ||
"time" | ||
) | ||
|
||
func ExampleParse(myToken string, myLookupKey func(interface{}) (interface{}, error)) { | ||
token, err := jwt.Parse(myToken, func(token *jwt.Token) (interface{}, error) { | ||
return myLookupKey(token.Header["kid"]) | ||
}) | ||
|
||
if err == nil && token.Valid { | ||
fmt.Println("Your token is valid. I like your style.") | ||
} else { | ||
fmt.Println("This token is terrible! I cannot accept this.") | ||
} | ||
} | ||
|
||
func ExampleNew(mySigningKey string) (string, error) { | ||
// Create the token | ||
token := jwt.New(jwt.SigningMethodHS256) | ||
// Set some claims | ||
token.Claims["foo"] = "bar" | ||
token.Claims["exp"] = time.Now().Add(time.Hour * 72).Unix() | ||
// Sign and get the complete encoded token as a string | ||
tokenString, err := token.SignedString(mySigningKey) | ||
return tokenString, err | ||
} |