https://github.com/reecerussell/gojwt
A simple, extendible JSON-Web-Token library, written in Golang with no third-party dependencies (kind of).
https://github.com/reecerussell/gojwt
golang jwt
Last synced: 11 months ago
JSON representation
A simple, extendible JSON-Web-Token library, written in Golang with no third-party dependencies (kind of).
- Host: GitHub
- URL: https://github.com/reecerussell/gojwt
- Owner: reecerussell
- License: mit
- Created: 2020-12-08T12:16:48.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-06-20T21:24:52.000Z (about 4 years ago)
- Last Synced: 2024-06-21T13:12:02.981Z (about 2 years ago)
- Topics: golang, jwt
- Language: Go
- Homepage:
- Size: 73.2 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://goreportcard.com/badge/github.com/reecerussell/gojwt)
[](https://codecov.io/gh/reecerussell/gojwt)
[](https://godoc.org/github.com/reecerussell/gojwt)
# GOJWT
A simple, extendible JSON-Web-Token library, written in Golang with no third-party dependencies.
## Installation
Simply, just run this command to install the package into your module.
```
$ go get -u github.com/reecerussell/gojwt
```
## Supported Algorithms
- [RSA](/rsa)
- [AWS KMS](/kms)
## Usage
This package is based on a JWt builder object, which is used to construct the token and sign it. And an algorithm interface, which allows abstractions to be created to support many differnt signing algorithms.
Here is a basic example of using an algorithm and builder:
```go
// Initiating an Algorithm, in this case RSA.
const myPrivateKeyFile string = "./super_secret_key.pem"
alg, err := rsa.NewFromFile(myPrivateKeyFile, crypto.SHA256)
if err != nil {
panic(err)
}
// Creating a new builder object, then adding some claims.
builder, err := gojwt.New(alg)
if err != nil {
panic(err)
}
builder.AddClaim("name", "John Doe").
SetExpiry(time.Now().Add(1 * time.Hour))
// Finally, building the token.
token, err := builder.Build()
if err != nil {
panic(err)
}
fmt.Println(token)
```