Skip to content

Commit

Permalink
add simple parse example
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg committed Oct 5, 2019
1 parent 8703592 commit 4b53f32
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions example_parse_test.go
@@ -0,0 +1,30 @@
package jwt_test

import (
"fmt"

"github.com/cristalhq/jwt"
)

func Example_ParseSimple() {
t := `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhZG1pbiIsImp0aSI6InJhbmRvbS11bmlxdWUtc3RyaW5nIn0.dv9-XpY9P8ypm1uWQwB6eKvq3jeyodLA7brhjsf4JVs`

token, err := jwt.Parse([]byte(t))
if err != nil {
fmt.Printf("parse err: %q", err)
return
}

fmt.Printf("Algorithm %v\n", token.Header().Algorithm)
fmt.Printf("Type %v\n", token.Header().Type)
fmt.Printf("Claims %v\n", string(token.RawClaims()))
fmt.Printf("Payload %v\n", string(token.Payload()))
fmt.Printf("Token %v\n", string(token.Raw()))

// Output:
// Algorithm HS256
// Type JWT
// Claims {"aud":"admin","jti":"random-unique-string"}
// Payload eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhZG1pbiIsImp0aSI6InJhbmRvbS11bmlxdWUtc3RyaW5nIn0
// Token eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhZG1pbiIsImp0aSI6InJhbmRvbS11bmlxdWUtc3RyaW5nIn0.dv9-XpY9P8ypm1uWQwB6eKvq3jeyodLA7brhjsf4JVs
}

0 comments on commit 4b53f32

Please sign in to comment.