https://github.com/legzdev/go-jwt
Simple, minimal and zero dependency Go JWT library
https://github.com/legzdev/go-jwt
go jwt
Last synced: about 1 year ago
JSON representation
Simple, minimal and zero dependency Go JWT library
- Host: GitHub
- URL: https://github.com/legzdev/go-jwt
- Owner: legzdev
- License: mit
- Created: 2024-06-23T17:08:09.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-31T05:24:07.000Z (almost 2 years ago)
- Last Synced: 2025-05-31T11:32:08.971Z (about 1 year ago)
- Topics: go, jwt
- Language: Go
- Homepage:
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
go-jwt
Simple, minimal and zero dependency Go JWT library.
[](https://go.dev)
[](https://pkg.go.dev/github.com/ghostsama2503/go-jwt)
[](https://jwt.io)
## Installation
```shell
go get -u github.com/ghostsama2503/go-jwt
```
## Building and signing a token
```go
package main
import (
"fmt"
"time"
"github.com/ghostsama2503/go-jwt"
)
func main() {
secretKey := []byte("secret")
currentTime := time.Now().UTC()
claims := &jwt.CommonClaims{
Subject: "test",
ExpirationTime: currentTime.AddDate(0, 1, 0).Unix(),
IssuedAtTime: currentTime.Unix(),
}
token := jwt.New(claims)
signedToken, err := token.Signed(secretKey)
if err != nil {
panic(err)
}
fmt.Println(signedToken)
}
```
## Parsing and validating a token
```go
package main
import (
"fmt"
"os"
"github.com/ghostsama2503/go-jwt"
)
func main() {
secretKey := []byte("secret")
tokenString := os.Getenv("TOKEN")
token, err := jwt.Parse(tokenString)
if err != nil {
panic(err)
}
if err := token.Validate(secretKey); err != nil {
panic(err)
}
fmt.Println("valid token")
}
```
## Disclaimer
It's provided as-is, with no guarantees or warranties. It's a lightweight and easy-to-use solution for basic needs. For more robust solutions, please consider alternatives like [golang-jwt/jwt](https://github.com/golang-jwt/jwt).