sshjwt

package module
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 22, 2023 License: MIT Imports: 6 Imported by: 0

README

Go Reference Github Workflow codecov

ssh-jwt

A library and command to generate jwt tokens using ssh key or ssh-agent

Usage

Library Usage

import as sshjwt "go.ptx.dk/sh-jwt"

Sign token

The following example connects to the ssh-agent and signs a token with the first available key.

	agent, err := sshjwt.DefaultAgent()
	if err != nil {
		return err
	}
	key, err := agent.FirstKey()
	if err != nil {
		return err
	}
	claims := jwt.MapClaims{
		"email": "peter@ptx.dk",
	}
	token := jwt.NewWithClaims(sshjwt.SSHSigningMethod, claims)
	str, err := token.SignedString(key)
	if err != nil {
		return err
	}
Verify

The following example verifies a token using any of the keys loaded in the ssh agent

	sshjwt.RegisterSigner() // Registers the SSHSigningMethod as the default for RS256 tokens 

	agent, err := sshjwt.DefaultAgent()
	if err != nil {
		return err
	}
	tok, err := jwt.Parse(token, func(token *jwt.Token) (interface{}, error) {
		return agent.AllKeys()
	})
Cli command
Sign claims

ssh-jwt sign key=value

Verify

ssh-jwt verify <token>

TODO

  • Create upstream patch to fix type of agent.NewKeyring (it should be ExtendedAgent instead of Agent)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SSHSigningMethod *sshSigner

Functions

func RegisterSigner

func RegisterSigner()

Types

type Agent

type Agent interface {
	FirstKey() (*keyWrapper, error)
	AllKeys() ([]*keyWrapper, error)
}

func DefaultAgent

func DefaultAgent() (Agent, error)

type Keyring

type Keyring interface {
	Agent
	AddKey(key sshagent.AddedKey) error
}

func NewKeyring

func NewKeyring() Keyring

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL