token

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2021 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PayloadSize defines how many bytes there are in payload
	PayloadSize = UnixTimestampSize + TokenAudienceSize

	// PayloadBase64Size is size of Payload in Base64 format(with padding)
	PayloadBase64Size = (PayloadSize + 2) / 3 * 4
)
View Source
const (
	// SignatureSize is size of token signature
	SignatureSize = sha256.Size

	// SignatureBase64Size is size of Signature in Base64 format(with padding)
	SignatureBase64Size = (SignatureSize + 2) / 3 * 4
)
View Source
const (
	// SignedSize is size of signed token
	SignedSize = SignatureSize + PayloadSize

	// SignedBase64Size is size of Signed token in Base64 format(with padding)
	SignedBase64Size = (SignedSize + 2) / 3 * 4
)
View Source
const (
	// AuthorizationCodeDuration defines expire duration for Authorization Code
	AuthorizationCodeDuration = time.Minute * 10
	// AccessTokenDuration defines expire duration for Access Token
	AccessTokenDuration = time.Hour

	// TokenAudienceSize is fixed size of Audience in Token
	TokenAudienceSize = 36

	// UnixTimestampSize says how many bytes there are required to store single unix timestamp
	UnixTimestampSize = 32 / 8
)

Variables

This section is empty.

Functions

func ExtractHeaderToken

func ExtractHeaderToken(r *http.Request) *string

ExtractHeaderToken extracts Bearer authorization token

Types

type Parsed

type Parsed struct {
	// Audience Must have fixed size of TokenAudienceSize
	Audience []byte
	// ExpiresAt is unix timestamp
	ExpiresAt uint32
}

Parsed is parsed token

func (Parsed) Equal

func (t Parsed) Equal(t2 Parsed) bool

Equal checks equality of tokens

func (Parsed) Payload

func (t Parsed) Payload() (b Payload)

Payload retursn payload of the token

func (Parsed) Sign

func (t Parsed) Sign(key []byte) (token Signed, err error)

Sign takes token Payload and then signs it and returns the signed token

func (Parsed) Signed

func (t Parsed) Signed(sig Signature) (s Signed)

Signed takes payload at appends it after signature

func (Parsed) Verify

func (t Parsed) Verify(key []byte, sig Signature) error

Verify verifies if parsed token is signed by signature passed via argument

type Payload

type Payload [PayloadSize]byte

Payload is payload of token

func NewPayloadFromBase64

func NewPayloadFromBase64(b64 []byte) (p Payload, err error)

NewPayloadFromBase64 parses base64 payload and returns Payload

func (Payload) Base64

func (p Payload) Base64() []byte

Base64 encodes Payload to base64 format

func (Payload) Equal

func (p Payload) Equal(p2 Payload) bool

Equal checks equality of tokens

func (Payload) Parse

func (p Payload) Parse() Parsed

Parse parses token to struct

func (Payload) Sign

func (p Payload) Sign(key []byte) (Signed, error)

Sign returns signature of token

func (Payload) Signed

func (p Payload) Signed(sig Signature) (signed Signed)

Signed converts Payload to Signed token

func (Payload) Verify

func (p Payload) Verify(key []byte, sig Signature) error

Verify verifies if Payload is signed by signature passed via argument

type Signature

type Signature [SignatureSize]byte

Signature is only signature of token

func NewSignatureFromBase64

func NewSignatureFromBase64(b64 []byte) (s Signature, err error)

NewSignatureFromBase64 parses base64 signature and returns Signature

func (Signature) Base64

func (s Signature) Base64() []byte

Base64 encodes signature to base64 format

func (Signature) Equal

func (s Signature) Equal(s2 Signature) bool

Equal checks equality of two signatures

type Signed

type Signed [SignedSize]byte

Signed is signed token

func NewSignedFromBase64

func NewSignedFromBase64(b64 []byte) (s Signed, err error)

NewSignedFromBase64 parses base64 and returns it in signed format

func NewSignedFromBase64WithVerify

func NewSignedFromBase64WithVerify(key []byte, b64 []byte) (s Signed, err error)

NewSignedFromBase64WithVerify parses base64 and returns it in signed format and also verifies if its valid

func (Signed) Base64

func (s Signed) Base64() []byte

Base64 encodes signed token to base64 format

func (Signed) Equal

func (s Signed) Equal(s2 Signed) bool

Equal checks equality with another signed token

func (Signed) Parse

func (s Signed) Parse() Parsed

Parse converts signed token to parsed token

func (Signed) Payload

func (s Signed) Payload() (p Payload)

Payload returns payload from signed token

func (Signed) Signature

func (s Signed) Signature() (sig Signature)

Signature converts Signed token to signature

func (Signed) Verify

func (s Signed) Verify(key []byte) error

Verify verifies token and returns nil if its valid

Jump to

Keyboard shortcuts

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