Documentation
¶
Overview ¶
Package msgraph implements the provider interfaces on Microsoft Graph (Microsoft 365 / Exchange Online) with delegated, device-code auth.
Index ¶
- Constants
- func Scopes(m policy.Mode) []string
- type Config
- type DeviceCodeInfo
- type LoginParams
- type LoginResult
- type Provider
- func (p *Provider) CreateDraft(ctx context.Context, in provider.DraftInput) (*provider.Message, error)
- func (p *Provider) CreateForwardDraft(ctx context.Context, in provider.ForwardInput) (*provider.Message, error)
- func (p *Provider) CreateReplyDraft(ctx context.Context, in provider.ReplyInput) (*provider.Message, error)
- func (p *Provider) DeleteDraft(ctx context.Context, id string) error
- func (p *Provider) Get(ctx context.Context, id string, o provider.GetOptions) (*provider.Message, error)
- func (p *Provider) GetAttachment(ctx context.Context, id, aid string) (*provider.Attachment, error)
- func (p *Provider) List(ctx context.Context, o provider.ListOptions) (*provider.Page, error)
- func (p *Provider) ListAttachments(ctx context.Context, id string) ([]provider.AttachmentMeta, error)
- func (p *Provider) ListDrafts(ctx context.Context, o provider.ListOptions) (*provider.Page, error)
- func (p *Provider) Mark(ctx context.Context, id string, o provider.MarkOptions) (*provider.Message, error)
- func (p *Provider) Move(ctx context.Context, id, dest string) (*provider.Message, error)
- func (p *Provider) Name() string
- func (p *Provider) Raw(ctx context.Context, r provider.RawRequest) (*provider.RawResponse, error)
- func (p *Provider) Relabel(ctx context.Context, id string, add, remove []string) (*provider.Message, error)
- func (p *Provider) Search(ctx context.Context, o provider.SearchOptions) (*provider.Page, error)
- func (p *Provider) Send(ctx context.Context, id string) (*provider.SendResult, error)
- func (p *Provider) Sync(ctx context.Context, o provider.SyncOptions) (*provider.SyncResult, error)
- func (p *Provider) Thread(ctx context.Context, threadID string, limit int) ([]provider.Message, error)
- func (p *Provider) UpdateDraft(ctx context.Context, id string, u provider.DraftUpdate) (*provider.Message, error)
- type TokenSource
Constants ¶
const ( Name = "msgraph" DefaultTenant = "organizations" // work/school accounts only; never "common" )
const ( FlowAuthCode = "auth-code" // authorization code + PKCE (default) FlowDevice = "device" // device code; blocked by Entra Security Defaults )
Login flows.
const DefaultBaseURL = "https://graph.microsoft.com/v1.0"
const MaxSimpleAttachment = 3 << 20
MaxSimpleAttachment is the largest attachment sent in one POST. Larger files would need an upload session, which is not implemented.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DeviceCodeInfo ¶
type DeviceCodeInfo struct {
VerificationURI string `json:"verification_uri"`
UserCode string `json:"user_code"`
ExpiresIn int `json:"expires_in"`
Message string `json:"message"`
}
DeviceCodeInfo is what the human needs to complete login.
type LoginParams ¶
type LoginParams struct {
Store *auth.Store
Account *auth.Account // Alias, Mode, TenantID, ClientID set
HTTP *http.Client
BaseURL string // Graph base, for /me
UserAgent string
Flow string // FlowAuthCode (default) or FlowDevice
// Auth code flow.
Manual bool // print the URL, read the pasted redirect URL from Stdin
Stdin io.Reader // for Manual
OnPrompt func(oauthflow.Prompt) error
OpenBrowser func(string) error // loopback only
// Device code flow: called once the code is available, before blocking.
OnDeviceCode func(DeviceCodeInfo) error
}
type LoginResult ¶
func Login ¶
func Login(ctx context.Context, p LoginParams) (*LoginResult, error)
Login signs the user in (auth code + PKCE by default, device code on request), then locks the account to the mailbox returned by /me. The previous token cache for the alias is discarded.
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
func (*Provider) CreateDraft ¶
func (*Provider) CreateForwardDraft ¶
func (*Provider) CreateReplyDraft ¶
func (p *Provider) CreateReplyDraft(ctx context.Context, in provider.ReplyInput) (*provider.Message, error)
CreateReplyDraft uses createReply/createReplyAll so Exchange sets In-Reply-To/References and quotes the original. The agent's text goes in `comment`, which Graph places above the quote; a separate PATCH of the body would replace the quote and could leave an empty draft behind if it failed.
func (*Provider) Get ¶
func (p *Provider) Get(ctx context.Context, id string, o provider.GetOptions) (*provider.Message, error)
Get fetches one message with its body in the stored content type. HTML is returned as HTML on purpose: the service derives text from it locally so hidden text is stripped (Graph's own text conversion keeps hidden text).
func (*Provider) GetAttachment ¶
func (*Provider) List ¶
List lists a folder newest first. A label that is not a folder is treated as an Outlook category.
Graph rejects $filter + $orderby ("InefficientFilter") unless the $orderby property also leads the $filter, so receivedDateTime always comes first.
func (*Provider) ListAttachments ¶
func (*Provider) ListDrafts ¶
func (*Provider) Raw ¶
func (p *Provider) Raw(ctx context.Context, r provider.RawRequest) (*provider.RawResponse, error)
Raw allows only paths under /me or /users/<locked account>; the policy layer has already checked the method against the mode.
func (*Provider) Relabel ¶
func (p *Provider) Relabel(ctx context.Context, id string, add, remove []string) (*provider.Message, error)
Relabel edits Outlook categories. Reserved labels are folders: use move.
func (*Provider) Search ¶
Search uses $search (KQL). Graph forbids combining it with $filter or $orderby; results come back by relevance/date as Graph decides.
func (*Provider) Send ¶
Send sends an existing draft. Graph answers 202 with no body and the sent copy gets a new id, so the result carries the draft's internetMessageId (assigned when the draft was created) instead.
func (*Provider) Sync ¶
func (p *Provider) Sync(ctx context.Context, o provider.SyncOptions) (*provider.SyncResult, error)
Sync uses messages/delta on the folder. The first run asks for mail received from now on (so the baseline is cheap) and returns nothing. Delta also reports read/flag changes on older mail; only messages received after the watermark count as new.
type TokenSource ¶
TokenSource returns a valid access token for Graph.
func NewTokenSource ¶
NewTokenSource returns a TokenSource for a logged-in msgraph account.