msgraph

package
v2.0.4-main.3 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 25 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package msgraph reads what Microsoft Graph posts about the subscriptions an app keeps: the check of an address Graph asks for before it makes a subscription, the change notifications of a batch with the secret each carries, the news of the subscriptions themselves, the resource data a rich notification carries encrypted for the app, the tokens that prove Microsoft sent it, and how long Graph lets a subscription of each resource last. It knows nothing of where subscriptions are kept: what a receiver needs of them is a Book

Index

Constants

View Source
const (
	// Graph asks the app to sign the subscription in again, which a renewal does
	Reauthorize = "reauthorizationRequired"
	// Graph removed the subscription, which the app makes again
	Removed = "subscriptionRemoved"
	// Graph could not deliver some notifications, so what changed meanwhile reached the app by no notification
	Missed = "missed"
)

News Graph posts of a subscription rather than of a change, as its lifecycle event names it

View Source
const (
	Created = "created"
	Updated = "updated"
	Deleted = "deleted"
)

Kinds of change a subscription tells of

View Source
const DefaultLimit = 1 << 20

Largest batch taken when the receiver names no limit, as alpha took them

View Source
const KeyBits = 3072

Bits of the key a certificate is made with: Graph takes RSA keys of 2048 to 4096 bits

View Source
const KeysAddress = "https://login.microsoftonline.com/common/discovery/v2.0/keys"

Where Microsoft publishes the keys its identity platform signs tokens with, which turn over daily

View Source
const Publisher = "0bf30f3b-4a52-48df-9a82-234910c4a086"

The app of Microsoft Graph's change notifications, which every validation token names as the one that asked for it

View Source
const Shortest = 45 * time.Minute

Shortest lifetime Graph gives a subscription: one asked to end sooner ends 45 minutes after the request

Variables

View Source
var (
	ErrUnreadable = errors.New("the resource data is not base64")
	ErrSignature  = errors.New("the resource data does not match its signature, so it was changed on its way")
	ErrDecrypt    = errors.New("the resource data does not decrypt with the key of its certificate")
)

Why resource data could not be read: it does not say what it is, its signature does not match, or it does not decrypt

The kinds of change Graph tells of, in the order they are said

Functions

func ChangeFor

func ChangeFor(resource string) string

The change Graph tells of for a resource when none is named: created for the collections of transcripts, recordings and call records, updated for the rest, as alpha chose

func ChangesOf

func ChangesOf(resource string, words []string) ([]string, []string)

The kinds of change of a list, each known one once, in Graph's order, Graph's own for the resource when the list names none; and the words that name no kind

func CheckToken

func CheckToken(token string, keys Keys, apps, tenants []string, now time.Time) (string, error)

Checks a validation token of a batch of rich notifications as Graph asks: signed with RS256 by a key of Microsoft's, within its time, for one of the apps, issued by Microsoft for its tenant (one of the tenants when any is named), and asked for by Graph's change notifications. The tenant it was issued for, or what is wrong with it

func Decrypt

func Decrypt(content Content, key *rsa.PrivateKey) ([]byte, error)

The resource data Graph encrypted, as JSON: its key decrypted with the private key (RSA-OAEP, SHA-1), its signature checked against the data (HMAC-SHA256 under that key) before anything is decrypted, then the data decrypted (AES-CBC, PKCS #7, the first 16 bytes of the key as the vector)

func Longest

func Longest(resource string, data bool) time.Duration

Longest a subscription of the resource may last, as Graph's table has it; with resource data, an Outlook message, event or contact lasts a day at most

func ReceiptKey

func ReceiptKey(n Notification) string

Key a notification is known by when it comes again: Graph's id of it, else a digest of the notification as it came, its keys in order

func StateMatches

func StateMatches(n Notification, secret string) bool

Whether the secret the notification carries is the subscription's, compared in constant time; never for an empty one

func Under

func Under(resource, subscribed string) bool

Whether the resource a notification names lies under the one subscribed to: the same, below it, one of its items by id, or, for the collections Graph tells of across an organisation (every transcript, every recording, every call record), an item of that kind under any meeting

func Until

func Until(resource string, data bool, now time.Time) time.Time

When a subscription of the resource made or renewed now should end: as late as Graph lets it, five minutes short of that so a clock that runs ahead is no refusal, never under Graph's shortest

Types

type Book

type Book interface {
	// The secret notifications of the subscription carry and the resource it tells of; false for a subscription the app does not keep
	Subscription(id string) (secret, resource string, ok bool)
	// Whether a notification of the key was taken before
	Taken(key string) bool
}

What a receiver knows of the subscriptions a batch may name

type Certificate

type Certificate struct {
	// What subscriptions name it by, 128 characters at most
	ID string `json:"id"`
	// The certificate and its private key, DER as X.509 and PKCS #8 write them
	Cert []byte    `json:"certificate"`
	Key  []byte    `json:"key"`
	Made time.Time `json:"made"`
}

A certificate whose public key Graph encrypts the resource data of rich notifications with, and the private key that decrypts it

func NewCertificate

func NewCertificate(id string, now time.Time) (Certificate, error)

Makes a self-signed certificate of a new RSA key, named by the id

func (Certificate) Encoded

func (c Certificate) Encoded() string

The certificate as a subscription hands it to Graph: base64 of its DER, the public key alone

func (Certificate) Private

func (c Certificate) Private() (*rsa.PrivateKey, error)

The private key of the certificate

func (Certificate) Thumbprint

func (c Certificate) Thumbprint() string

The SHA-1 digest of the certificate in upper case hexadecimal, as Graph names it beside its id

type Content

type Content struct {
	Data        string `json:"data"`
	Signature   string `json:"dataSignature"`
	Key         string `json:"dataKey"`
	Certificate string `json:"encryptionCertificateId"`
	Thumbprint  string `json:"encryptionCertificateThumbprint,omitempty"`
}

Resource data Graph encrypted for the app: the data, its signature and the key it was encrypted with, each base64, and the certificate whose public key encrypted that key

type Keys

type Keys map[string]*rsa.PublicKey

Signing keys of Microsoft's identity platform, by their key id

func ParseKeys

func ParseKeys(data []byte) (Keys, error)

The RSA keys of a JSON Web Key Set, as Microsoft publishes them

type Notification

type Notification struct {
	ID           string `json:"id,omitempty"`
	Subscription string `json:"subscriptionId"`
	// When the subscription ends as Graph has it
	Ends        string         `json:"subscriptionExpirationDateTime,omitempty"`
	ClientState string         `json:"clientState,omitempty"`
	Change      string         `json:"changeType,omitempty"`
	Resource    string         `json:"resource,omitempty"`
	Tenant      string         `json:"tenantId,omitempty"`
	Lifecycle   string         `json:"lifecycleEvent,omitempty"`
	Data        map[string]any `json:"resourceData,omitempty"`
	// The changed resource itself, encrypted for the app, in a rich notification
	Encrypted *Content `json:"encryptedContent,omitempty"`
	// The changed resource as JSON once decrypted, empty for a notification that carried none
	Decrypted json.RawMessage `json:"-"`
	// The notification whole, as it came
	Raw json.RawMessage `json:"-"`
}

A notification of a change, or news of a subscription, as Graph posts it

type Received

type Received struct {
	// Status, content type and body of the answer
	Status int
	Type   string
	Body   string
	// It was Graph's check of the address, answered with its token
	Validation bool
	// Notifications of changes and news of subscriptions taken, each the first of its key, its secret the subscription's
	Changes, Lifecycle []Notification
	// Tokens a batch of rich notifications carries, which say Microsoft sent it
	Tokens []string
	// Notifications taken before, refused for their secret or their subscription, and those that read as none or of another resource
	Duplicates, Refused, Other int
}

What came of a request: what it is answered with, and what of it was taken

func Receive

func Receive(r Request, book Book) Received

Reads what Graph made of the address: its check of a new subscription's address answered with its token as plain text, else a batch of notifications, each taken only when its subscription is kept, its secret is that subscription's and it was not taken before. The answer is alpha's: 202 when any was taken or known, 403 when every one failed its secret, 400 otherwise; 413 past the limit

func (Received) Answer

func (r Received) Answer() int

Status a batch is answered with for what came of it, as alpha answered: 202 when any was taken or known, 403 when every one failed its secret, 400 otherwise

func (Received) Taken

func (r Received) Taken() int

How many notifications were taken

type Request

type Request struct {
	Method string
	Query  url.Values
	Body   io.Reader
	// Most bytes of a batch, DefaultLimit when zero
	Limit int64
}

A request Graph made of the receiver's address

Jump to

Keyboard shortcuts

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