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
- Variables
- func ChangeFor(resource string) string
- func ChangesOf(resource string, words []string) ([]string, []string)
- func CheckToken(token string, keys Keys, apps, tenants []string, now time.Time) (string, error)
- func Decrypt(content Content, key *rsa.PrivateKey) ([]byte, error)
- func Longest(resource string, data bool) time.Duration
- func ReceiptKey(n Notification) string
- func StateMatches(n Notification, secret string) bool
- func Under(resource, subscribed string) bool
- func Until(resource string, data bool, now time.Time) time.Time
- type Book
- type Certificate
- type Content
- type Keys
- type Notification
- type Received
- type Request
Constants ¶
const ( 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
const ( Created = "created" Updated = "updated" Deleted = "deleted" )
Kinds of change a subscription tells of
const DefaultLimit = 1 << 20
Largest batch taken when the receiver names no limit, as alpha took them
const KeyBits = 3072
Bits of the key a certificate is made with: Graph takes RSA keys of 2048 to 4096 bits
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
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
const Shortest = 45 * time.Minute
Shortest lifetime Graph gives a subscription: one asked to end sooner ends 45 minutes after the request
Variables ¶
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
var Changes = []string{Created, Updated, Deleted}
The kinds of change Graph tells of, in the order they are said
Functions ¶
func ChangeFor ¶
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 ¶
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 ¶
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 ¶
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
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 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 ¶
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