jwt_licence

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2022 License: MIT Imports: 6 Imported by: 0

README

Simple JWT based licence

Installing

$ go get github.com/IgorPidik/go-jwt-licence

Importing

import licence "github.com/IgorPidik/go-jwt-licence"

Generating key pair

Private key:

$ openssl genrsa -out keys/id_rsa 4096

Public key:

$ openssl rsa -in keys/id_rsa -pubout -out keys/id_rsa.pub

Generating licence

generator, generatorErr := licence.NewLicenceGenerator("keys/id_rsa")
check(generatorErr)

expiresAt, parsingErr := time.Parse("2006-01-02", "2022-12-31")
check(parsingErr)

licenceData := &licence.LicenceData{
    ExpiresAt: expiresAt,
    Subject:   "Licence subject",
    Issuer:    "Licence issuer",
}

licence, licenceErr := generator.CreateLicence(licenceData)
check(licenceErr)

Validating licence

validator, validatorErr := licence.NewLicenceValidator("keys/id_rsa.pub")
check(validatorErr)
licenceData, licenceErr := validator.ValidateLicence(licence)
check(licenceErr)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LicenceData

type LicenceData struct {
	ExpiresAt time.Time
	Subject   string
	Issuer    string
}

type LicenceGenerator

type LicenceGenerator struct {
	PrivateKey *rsa.PrivateKey
}

func NewLicenceGenerator

func NewLicenceGenerator(privateKeyPath string) (*LicenceGenerator, error)

func (*LicenceGenerator) CreateLicence

func (lg *LicenceGenerator) CreateLicence(data *LicenceData) (string, error)

type LicenceValidator

type LicenceValidator struct {
	PublicKey *rsa.PublicKey
}

func NewLicenceValidator

func NewLicenceValidator(publicKeyPath string) (*LicenceValidator, error)

func NewLicenceValidatorFromPublicKey added in v0.1.2

func NewLicenceValidatorFromPublicKey(publicKey *rsa.PublicKey) *LicenceValidator

func (*LicenceValidator) ValidateLicence

func (lv *LicenceValidator) ValidateLicence(licence string) (*LicenceData, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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