Skip to content
This repository was archived by the owner on Jul 28, 2020. It is now read-only.
/ jwt Public archive

JSON Web Token library for Google Go.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

zhevron/jwt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

b558688 · May 15, 2019

History

51 Commits
Apr 15, 2015
Apr 15, 2015
Apr 15, 2015
May 15, 2019
May 15, 2019
May 15, 2019
May 15, 2019
May 15, 2019
May 15, 2019
Apr 14, 2015
Apr 15, 2015
Apr 15, 2015
Apr 15, 2015

Repository files navigation

JSON Web Tokens for Go

Coverage Status Build Status GoDoc Gitter

jwt is a simple library for handling JSON Web Tokens in Go.
The library is developed based on draft-ietf-oauth-json-web-token-32.

Installation

You can install the library using the standard go get command:

go get gopkg.in/zhevron/jwt.v1

Note: This package requires Go 1.3 or higher.

Examples

JSON Web Token (HMAC, HS256)

import (
  "fmt"

  "gopkg.in/zhevron/jwt.v1"
)

func main() {
  key := "secret"

  token := jwt.NewToken()
  token.Claims["username"] = "my_username"

  tokenstring, err := token.Sign(key)
  if err != nil {
    panic(err)
  }

  token, err = jwt.DecodeToken(tokenstring, jwt.HS256, key)
  if err != nil {
    panic(err)
  }

  fmt.Printf("Your username is: %s\n", token.Claims["username"])
}

JSON Web Token (RSA, RS256)

import (
  "fmt"

  "gopkg.in/zhevron/jwt.v1"
)

func main() {
  privateKey = `-----BEGIN RSA PRIVATE KEY-----
myprivatekeyhere
-----END RSA PRIVATE KEY-----`
  publicKey = `-----BEGIN PUBLIC KEY-----
mypublickeyhere  
-----END PUBLIC KEY-----`

  token := jwt.NewToken()
  token.Algorithm = jwt.RS256
  token.Claims["username"] = "my_username"

  tokenstring, err := token.Sign(privateKey)
  if err != nil {
    panic(err)
  }

  token, err = jwt.DecodeToken(tokenstring, jwt.RS256, publicKey)
  if err != nil {
    panic(err)
  }

  fmt.Printf("Your username is: %s\n", token.Claims["username"])
}

JSON Web Token (ECDSA, ES256)

import (
  "fmt"

  "gopkg.in/zhevron/jwt.v1"
)

func main() {
  privateKey = `-----BEGIN EC PRIVATE KEY-----
myprivatekeyhere
-----END EC PRIVATE KEY-----`
  publicKey = `-----BEGIN PUBLIC KEY-----
mypublickeyhere  
-----END PUBLIC KEY-----`

  token := jwt.NewToken()
  token.Algorithm = jwt.ES256
  token.Claims["username"] = "my_username"

  tokenstring, err := token.Sign(privateKey)
  if err != nil {
    panic(err)
  }

  token, err = jwt.DecodeToken(tokenstring, jwt.ES256, publicKey)
  if err != nil {
    panic(err)
  }

  fmt.Printf("Your username is: %s\n", token.Claims["username"])
}

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

JSON Web Token library for Google Go.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages