token

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 27, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TokenTimeout is the period of time in seconds that a token is valid for.
	// If the timestamp for token issue is not within the last hour, APNs
	// rejects subsequent push messages. This is set to under an hour so that
	// we generate a new token before the existing one expires.
	TokenTimeout = 3000
)

Variables

View Source
var (
	ErrAuthKeyNotPem   = errors.New("token: AuthKey must be a valid .p8 PEM file")
	ErrAuthKeyNotECDSA = errors.New("token: AuthKey must be of type ecdsa.PrivateKey")
	ErrAuthKeyNil      = errors.New("token: AuthKey was nil")
)

Possible errors when parsing a .p8 file.

Functions

func AuthKeyFromBytes

func AuthKeyFromBytes(bytes []byte) (*ecdsa.PrivateKey, error)

AuthKeyFromBytes loads a .p8 certificate from an in memory byte array and returns an *ecdsa.PrivateKey.

func AuthKeyFromFile

func AuthKeyFromFile(filename string) (*ecdsa.PrivateKey, error)

AuthKeyFromFile loads a .p8 certificate from a local file and returns a *ecdsa.PrivateKey.

Types

type Token

type Token struct {
	sync.Mutex
	AuthKey  *ecdsa.PrivateKey
	KeyID    string
	TeamID   string
	IssuedAt int64
	Bearer   string
}

Token represents an Apple Provider Authentication Token (JSON Web Token).

func (*Token) Expired

func (t *Token) Expired() bool

Expired checks to see if the token has expired.

func (*Token) Generate

func (t *Token) Generate() (bool, error)

Generate creates a new token.

func (*Token) GenerateIfExpired

func (t *Token) GenerateIfExpired() (bearer string)

GenerateIfExpired checks to see if the token is about to expire and generates a new token.

Jump to

Keyboard shortcuts

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