https://github.com/bwplotka/go-jwt
Golang JSON Web Token builder with easy to use API for JWS and nested JWT (JWS+JWE)
https://github.com/bwplotka/go-jwt
go jsonwebtoken jwe jws jwt
Last synced: 1 day ago
JSON representation
Golang JSON Web Token builder with easy to use API for JWS and nested JWT (JWS+JWE)
- Host: GitHub
- URL: https://github.com/bwplotka/go-jwt
- Owner: bwplotka
- License: apache-2.0
- Created: 2017-04-10T11:33:34.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-05-22T13:11:35.000Z (over 8 years ago)
- Last Synced: 2024-12-19T13:33:45.343Z (10 months ago)
- Topics: go, jsonwebtoken, jwe, jws, jwt
- Language: Go
- Size: 23.4 KB
- Stars: 3
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-jwt [](https://jwt.io)
[](https://travis-ci.org/Bplotka/go-jwt) [](https://goreportcard.com/report/github.com/Bplotka/go-jwt)
Golang JSON Web Token builder with easy to use API for JWS and nested JWT (JWS+JWE)It wraps and is inspired by [gopkg.in/square/go-jose.v2](https://github.com/square/go-jose/tree/v2.1.0) (especially `jwt` subpackage)
NOTE: Please, make sure you get fixed version of go-jose.v2. https://github.com/square/go-jose/issues/142
## Usage:
```go
package mainimport (
"fmt"
"github.com/Bplotka/go-jwt"
)func main() {
p := "some_payload"
cl := jwt.Claims{
// Your standard claims here...
}
b, err := jwt.NewDefaultBuilder() // or jwt.NewBuilder(rsaPrvKey, signAlg, keyAlg, contentAlg)
if err != nil {
// Handle error here...
}
token, err := b.SignedAndEncryptedJWT().
Claims(cl).
Payload(p).
CompactSerialize()
if err != nil {
// Handle error here...
}
// Generated valid nested JWT in `token` variable!
// (....)
// Let's revert the process:
obtainer := b.FromSignedAndEncryptedJWT(token)
var fetched string
err = obtainer.Payload(&fetched)
if err != nil {
// Handle error here..
}
// We have "some_payload" again in `fetched` variable.
fetchedStdClaims, err := obtainer.StdClaims()
if err != nil {
// Handle error here..
}
// We have our standard claims again in `fetchedStdClaims` variable.
fmt.Println(fetchedStdClaims.Issuer)
fmt.Println(fetchedStdClaims.Subject)
// ...
}
```