Skip to content

Repository files navigation

Go Report Card codecov Go Docs

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

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:

// 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)

About

A simple, extendible JSON-Web-Token library, written in Golang with no third-party dependencies (kind of).

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages