jwt

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2025 License: MIT Imports: 5 Imported by: 0

README

Jwt Issuer and Parser

This package provides a simple way to issue and parse JWT tokens.

Installation

go get github.com/nlgolib/jwt

Functionality Highlights

  • Claims object with standard jwt keys
  • Issue token with secret
  • Issue token with private RSA key
  • Parse token with secret
  • Parse token with private RSA key
  • Parse token with public RSA key
  • Parse token with unverified way

Documentation

Index

Constants

View Source
const (
	KeyIssuer         = "iss" // who issued the token
	KeySubject        = "sub" // subject of the token
	KeyAudience       = "aud" // who or what the token is intended for
	KeyExpirationTime = "exp" // expiration time, as unix time
	KeyNotBefore      = "nbf" // not before, as unix time
	KeyIssuedAt       = "iat" // issued at, as unix time
	KeyID             = "jti" // unique identifier for the token
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Claims

type Claims struct {
	// contains filtered or unexported fields
}

Claims represents the claims in a JWT

func NewClaims

func NewClaims() *Claims

func (*Claims) GetAudience

func (c *Claims) GetAudience() string

GetAudience gets the audience of the token audience is about who or what the token is intended for audience is the standard claim key: "aud"

func (*Claims) GetExpirationTime

func (c *Claims) GetExpirationTime() time.Time

GetExpirationTime gets the expiration time of the token, as unix time expiration time is the standard claim key: "exp"

func (*Claims) GetID

func (c *Claims) GetID() string

GetID gets the ID of the token ID is the standard claim key: "jti"

func (*Claims) GetIssuedAt

func (c *Claims) GetIssuedAt() time.Time

GetIssuedAt gets the issued at time of the token, as unix time issued at is the standard claim key: "iat"

func (*Claims) GetIssuer

func (c *Claims) GetIssuer() string

GetIssuer gets the issuer of the token issuer is about who issued the token issuer is the standard claim key: "iss"

func (*Claims) GetNotBefore

func (c *Claims) GetNotBefore() time.Time

GetNotBefore gets the not before time of the token, as unix time not before is about when the token is not valid yet not before is the standard claim key: "nbf"

func (*Claims) GetSubject

func (c *Claims) GetSubject() string

GetSubject gets the subject of the token subject is about who or what the token is intended for subject is the standard claim key: "sub"

func (*Claims) GetValue

func (c *Claims) GetValue(key string) any

GetValue gets the value of the claim

func (*Claims) SetAudience

func (c *Claims) SetAudience(audience string)

SetAudience sets the audience of the token audience is about who or what the token is intended for audience is the standard claim key: "aud"

func (*Claims) SetExpirationTime

func (c *Claims) SetExpirationTime(expirationTime time.Time)

SetExpirationTime sets the expiration time of the token, as unix time expiration time is the standard claim key: "exp"

func (*Claims) SetID

func (c *Claims) SetID(id string)

SetID sets the ID of the token ID is the standard claim key: "jti"

func (*Claims) SetIssuedAt

func (c *Claims) SetIssuedAt(issuedAt time.Time)

SetIssuedAt sets the issued at time of the token, as unix time issued at is the standard claim key: "iat"

func (*Claims) SetIssuer

func (c *Claims) SetIssuer(issuer string)

SetIssuer sets the issuer of the token issuer is about who issued the token issuer is the standard claim key: "iss"

func (*Claims) SetNotBefore

func (c *Claims) SetNotBefore(notBefore time.Time)

SetNotBefore sets the not before time of the token, as unix time not before is about when the token is not valid yet not before is the standard claim key: "nbf"

func (*Claims) SetSubject

func (c *Claims) SetSubject(subject string)

SetSubject sets the subject of the token subject is about who or what the token is intended for subject is the standard claim key: "sub"

func (*Claims) SetValue

func (c *Claims) SetValue(key string, value any)

SetValue sets the value of the claim

func (*Claims) WithPrivateRSA

func (c *Claims) WithPrivateRSA(privateKey *rsa.PrivateKey) *withPrivateRSA

func (*Claims) WithPublicRSA

func (c *Claims) WithPublicRSA(publicKey *rsa.PublicKey) *withPublicRSA

func (*Claims) WithSecret

func (c *Claims) WithSecret(secret string) *withSecret

func (*Claims) WithUnverified

func (c *Claims) WithUnverified() *withUnverified

Jump to

Keyboard shortcuts

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