Skip to content

A jwt-go extension that uses the Vault transit secret engine as signer

Notifications You must be signed in to change notification settings

cbws/go-jwt-vault

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Vault token signer for jwt-go

This an extension for the jwt-go token generation library that uses the Vault transit secret engine so sign tokens.

Example

package main

import (
	"context"
	"github.com/cbws/go-jwt-vault"
	"github.com/dgrijalva/jwt-go"
	vault "github.com/hashicorp/vault/api"
	"log"
)

func main() {
	vaultClient, err := vault.NewClient(vault.DefaultConfig())
	if err != nil {
		log.Fatalf("Could not create Vault client: %+v", err)
	}

	claims := jwt.StandardClaims{
		Subject: "test",
	}


	jwtToken := jwt.NewWithClaims(go_vault_jwt.SigningMethodVRS256, claims)

	key := go_vault_jwt.NewVaultContext(context.Background(), &go_vault_jwt.VaultConfig{
		KeyPath: "/transit",
		KeyName: "test-key",
		KeyVersion: 2,
		Client: vaultClient,
	})
	payload, err := jwtToken.SignedString(key)
	if err != nil {
		log.Fatalf("Could not create JWT token: %+v", err)
	}

	log.Printf("Token: %s", payload)
}

About

A jwt-go extension that uses the Vault transit secret engine as signer

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages