A Golang implementation of JSON Web Token (JWT) - RFC 7519.
Our support of Go versions is aligned with Go's version release policy. So we will support a major version of Go until there are two newer major releases.
With a correctly configured Go toolchain:
go get -u github.com/dmalix/gojwt
The library implements JWT Verification and Signing using the following algorithms:
JWS | Algorithm | Description |
---|---|---|
HS256 | HMAC256 | HMAC with SHA-256 |
HS512 | HMAC512 | HMAC with SHA-512 |
Create a new JWT instance and configure the parameters:
jwtInstance, err := gojwt.NewToken(&gojwt.Config{
Headers: gojwt.Headers{
Type: gojwt.TokenType,
SignatureAlgorithm: gojwt.TokenSignatureAlgorithmHS256,
},
Claims: gojwt.Claims{
Issuer: "some data",
Subject: "some subject",
},
ParseOptions: gojwt.ParseOptions{
RequiredHeaderContentType: true,
RequiredClaimIssuer: true,
RequiredClaimSubject: true,
RequiredClaimJwtId: true,
RequiredClaimData: true
},
TokenLifetimeSec: 100,
Key: "your-256-bit-secret",
})
if err != nil {
log.Fatal(err)
}
Create a new token:
jwt, err := jwtInstance.Create(&gojwt.Claims{
JwtId: "some Id",
Data: []byte("some dataset"),
})
if err != nil {
log.Fatal(err)
}
And so you can check and get data from the token:
jwt := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
jwtToken, codeError, err := jwtInstance.Parse(jwt)
if err != nil {
log.Fatalln(codeError, err)
}
If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker.
If you discover any security related issues, please email dmalix@yahoo.com instead of using the issue tracker.
This project is licensed under the MIT license. See the LICENSE file for more info.