jwt

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2024 License: MIT Imports: 8 Imported by: 0

README

JWT

JWT wrapper library which makes it simple to user ECDSA based JWT signing.

Usage
package main

import (
	"context"

	"github.com/infiniteloopcloud/jwt"
)

type token struct {
	token string `json:"token"`
}

func (t token) ClaimsParse() map[string]interface{} {
	return map[string]interface{}{
		"token": t.token,
    }
}

func main() {
	ctx := context.Background()
	t := token{
		token: "random_token",
    }

	m := jwt.Metadata{
		PrivateKey: "private_key",
		Issuer: "some issuer",
	}

	signed, _ := jwt.Create(ctx, m, t)
	claims, _ := jwt.Verify(ctx, m, signed)
	// Use the claims
}

Documentation

Overview

Package jwt provides secure signature-based token sharing with the client-side. Implements a JWT standard for providing this functionality.

Index

Constants

View Source
const DefaultPrivateKey = "" /* 164-byte string literal not displayed */

DefaultPrivateKey is for NON-PRODUCTION use

Variables

View Source
var (
	ErrJWTExpired      = errors.New("jwt expired")
	ErrInvalidAudience = errors.New("invalid audience")
)

Functions

func Create

func Create(ctx context.Context, meta Metadata, claimsContainer ...claimsParser) ([]byte, error)

Create actually creates a valid jwt with all necessary standards, and put all the claims into the payload. Also, setup jwt standard claims as well.

func Verify

func Verify(ctx context.Context, meta Metadata, t []byte) (*jwt.Claims, error)

Verify starts with the signature verification, then checking the jwt standard claims, finally returns the claims.

Types

type Metadata

type Metadata struct {
	PrivateKey string
	Issuer     string
	ClientHost string
}

Jump to

Keyboard shortcuts

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