graph

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package graph provides an HTTP client for Microsoft Graph API calls with built-in safety enforcement and incremental consent support.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckSafety

func CheckSafety(method string, allowWrites bool) error

CheckSafety enforces the write protection policy.

Default behavior (allowWrites=false): only GET, HEAD, OPTIONS are allowed. With --allow-writes: POST, PUT, PATCH are additionally allowed. DELETE is always rejected.

func FormatError

func FormatError(resp *Response) string

FormatError returns a user-friendly error message from a Graph API response.

func ParseRequiredScopes

func ParseRequiredScopes(body string) []string

ParseRequiredScopes attempts to extract required permission scopes from a 403 Forbidden response body. Graph API error messages often contain the required scopes in the error message text.

Types

type CallOptions

type CallOptions struct {
	Method     string
	URL        string // Can be a full URL or a relative path (e.g. "/me")
	Body       string
	Headers    map[string]string
	APIVersion string
	Select     string
	Filter     string
	Top        int
	Expand     string
	OrderBy    string
	Scopes     []string // Extra scopes to request
}

CallOptions configures a single Graph API request.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the Graph API HTTP client.

func NewClient

func NewClient(authClient auth.TokenProvider, cfg *config.Config, allowWrites bool) *Client

NewClient creates a new Graph API client.

func (*Client) Call

func (c *Client) Call(ctx context.Context, opts CallOptions) (*Response, error)

Call executes a Graph API request.

type GraphError

type GraphError struct {
	Error struct {
		Code       string `json:"code"`
		Message    string `json:"message"`
		InnerError *struct {
			Date            string `json:"date"`
			RequestID       string `json:"request-id"`
			ClientRequestID string `json:"client-request-id"`
		} `json:"innerError,omitempty"`
	} `json:"error"`
}

GraphError represents a Microsoft Graph API error response.

func ParseGraphError

func ParseGraphError(body string) *GraphError

ParseGraphError parses a Graph API error response body.

type Response

type Response struct {
	StatusCode int               `json:"statusCode"`
	Headers    map[string]string `json:"headers,omitempty"`
	Body       string            `json:"body"`
}

Response holds the Graph API response.

Jump to

Keyboard shortcuts

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