pushserver

package
v0.0.0-...-9b43f02 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2023 License: MIT, MIT Imports: 24 Imported by: 0

README

RFC8030 Web Push, RFC8292 VAPID, RFC8291 Web Push Encryption: Mock Server Implementation in Go

Subscription Receipt is not implemented.

License

MIT License

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrForbidden = errors.New("Message was not authenticated while it is required (RFC8292 4.2., Forbidden)")

ErrForbidden represents a Forbidden error defined in RFC8292 4.2 https://tools.ietf.org/html/rfc8292#section-4-2

View Source
var ErrInvalidData = errors.New("Invalid data")

ErrInvalidData is an error returned when encountered an invalid data.

View Source
var ErrSubscriptionInactive = errors.New("Push attempt to expired subscription")

ErrSubscriptionInactive is an error only used for OnInvalidPush callback argument. Passed when received a push to inactive push subscription.

View Source
var ErrSubscriptionNotFound = errors.New("No subscription found")

ErrSubscriptionNotFound is an error only used for OnInvalidPush callback argument. Passed when received a push to nonexistent push subscription.

View Source
var ErrUnauthorized = errors.New("Message was not authenticated while it is required (RFC8292 4.2., Unauthorized)")

ErrUnauthorized represents an Unauthorized error defined in RFC8292 4.2 https://tools.ietf.org/html/rfc8292#section-4-2

View Source
var ErrUnencrypted = errors.New("Message should be encrypted but was not")

ErrUnencrypted is an error returned when a message wasn't encrypted while required to do so.

View Source
var ErrUnexpectedAuthorizationHeader = errors.New(`invalid or unexpected Authorization header`)

ErrUnexpectedAuthorizationHeader is an error when encountered unexpected, invalid Authorization header.

View Source
var ErrUnexpectedToken = errors.New(`VAPID key validation failure`)

ErrUnexpectedToken is an error returned when given pubilc key doesn't comply RFC8292 or doesn't match to the known expected public key.

View Source
var ErrUnrestricted = errors.New("unrestricted subscription is not permitted (RFC8292 Section 4.)")

ErrUnrestricted is an error returned when a subscription is required to be restricted, but isn't restricted.

Functions

This section is empty.

Types

type Message

type Message struct {
	ID    string
	Body  []byte
	TTL   int64
	Topic string
	// contains filtered or unexported fields
}

Message is a message

func (*Message) GetPath

func (m *Message) GetPath() string

GetPath returns a HTTP path for this message

func (*Message) GetURL

func (m *Message) GetURL() string

GetURL returns a HTTP URL for this message

func (*Message) WasUnencrypted

func (m *Message) WasUnencrypted() bool

WasUnencrypted returns true when a message was not pushed with a encryption (RFC8291) and has a content.

type RawMessage

type RawMessage struct {
	Body  []byte
	TTL   int64
	Topic string

	Encoding string
}

RawMessage is a raw push message (might be encrypted) given at HTTP Push Request.

type Service

type Service struct {
	Origin string

	OnInvalidPush func(id string, err error)
	// contains filtered or unexported fields
}

Service is a web app of RFC8030, RFC8292 mock implementation

func NewService

func NewService(origin string, capa int64) *Service

NewService returns Service

func (*Service) GetSubscriptionByID

func (s *Service) GetSubscriptionByID(id string) *Subscription

GetSubscriptionByID finds a Subscription by its ID. nil when not exists.

func (*Service) HTTP

func (s *Service) HTTP() *mux.Router

HTTP returns a mux.Router to serve push server endpoints.

func (*Service) Subscribe

func (s *Service) Subscribe(option *SubscriptionOption, rejectUnencryptedMessage bool, rejectUnrestrictedSubscription bool) (*Subscription, error)

Subscribe returns a new push subscription. where encodedVapidPublicKey is an optional application server's base64 encoded VAPID public key. Error is only returned on cryptographic RNG failure or invalid option (VAPID public key) is given.

type Subscription

type Subscription struct {
	ID        string
	NumericID int64
	Audience  string

	// RejectUnencryptedMessage enables error when unencrypted messages (RFC8291) are pushed.
	RejectUnencryptedMessage bool
	// contains filtered or unexported fields
}

Subscription is a subscription.

func (*Subscription) Authenticate

func (sub *Subscription) Authenticate(authorization string) error

Authenticate verifies a VAPID authorization header. Returns an error when unauthorised.

func (*Subscription) Expire

func (sub *Subscription) Expire()

Expire invalidates a subscription and lets it inactive. Inactive push resource will return 404 at Service.

func (*Subscription) GetAuth

func (sub *Subscription) GetAuth() string

GetAuth returns a user-agent auth parameter; https://tools.ietf.org/html/rfc8291#section-2

func (*Subscription) GetChannel

func (sub *Subscription) GetChannel() <-chan *Message

GetChannel returns a chan to receive pushed message

func (*Subscription) GetP256DH

func (sub *Subscription) GetP256DH() string

GetP256DH returns a user-agent p256dh parameter; https://tools.ietf.org/html/rfc8291#section-2

func (*Subscription) GetPath

func (sub *Subscription) GetPath() string

GetPath returns a HTTP path for this subscription (push message request)

func (*Subscription) GetURL

func (sub *Subscription) GetURL() string

GetURL returns a HTTP URL for this subscription (push message request)

func (*Subscription) IsActive

func (sub *Subscription) IsActive() bool

IsActive returns true when a subscription is still active and not expired. See also Expire()

func (*Subscription) IsRestricted

func (sub *Subscription) IsRestricted() bool

IsRestricted returns true when a subscription is restricted to a specific application server with VAPID https://tools.ietf.org/html/rfc8292#section-4

type SubscriptionOption

type SubscriptionOption struct {
	Vapid string `json:"vapid,omitempty"`
}

SubscriptionOption is a struct represents application/webpush-options+json https://tools.ietf.org/html/rfc8292#section-4.1

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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