microsoft

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client provides Microsoft Graph API operations.

func NewClient

func NewClient(tokenProvider driven.TokenProvider, config *ClientConfig) *Client

NewClient creates a new Microsoft Graph API client.

func (*Client) GetDelta

func (c *Client) GetDelta(ctx context.Context, deltaLink string) (*DeltaResponse, error)

GetDelta retrieves changes in a drive using delta queries. If deltaLink is empty, starts a new delta query. Otherwise, uses the provided delta link.

func (*Client) GetDriveItem

func (c *Client) GetDriveItem(ctx context.Context, itemID string) (*DriveItem, error)

GetDriveItem retrieves a specific drive item.

func (*Client) GetDriveItemContent

func (c *Client) GetDriveItemContent(ctx context.Context, itemID string) ([]byte, error)

GetDriveItemContent downloads the content of a file. Returns the content as a byte slice.

func (*Client) GetDriveItems

func (c *Client) GetDriveItems(ctx context.Context, itemID string) (*DriveItemsResponse, error)

GetDriveItems retrieves items from a drive or folder.

func (*Client) GetMe

func (c *Client) GetMe(ctx context.Context) (*User, error)

GetMe retrieves the authenticated user's information.

func (*Client) GetNextPage

func (c *Client) GetNextPage(ctx context.Context, nextLink string, result interface{}) error

GetNextPage retrieves the next page of results using a nextLink URL.

type ClientConfig

type ClientConfig struct {
	// BaseURL is the base URL for Microsoft Graph API.
	// Defaults to https://graph.microsoft.com/v1.0
	BaseURL string

	// RateLimitRPS is the rate limit in requests per second.
	// Microsoft Graph has different rate limits per endpoint, but we use a conservative default.
	RateLimitRPS float64

	// RequestTimeout is the timeout for API requests.
	RequestTimeout time.Duration

	// MaxRetries is the maximum number of retry attempts for failed requests.
	MaxRetries int
}

ClientConfig contains configuration for the Microsoft Graph client.

func DefaultClientConfig

func DefaultClientConfig() *ClientConfig

DefaultClientConfig returns the default Microsoft Graph client configuration.

type DeletedFacet

type DeletedFacet struct {
	State string `json:"state,omitempty"`
}

DeletedFacet indicates an item has been deleted.

type DeltaResponse

type DeltaResponse struct {
	Value     []DriveItem `json:"value"`
	NextLink  string      `json:"@odata.nextLink,omitempty"`
	DeltaLink string      `json:"@odata.deltaLink,omitempty"`
}

DeltaResponse represents a response from a delta query.

type DriveItem

type DriveItem struct {
	ID                   string         `json:"id"`
	Name                 string         `json:"name"`
	Size                 int64          `json:"size,omitempty"`
	WebURL               string         `json:"webUrl"`
	CreatedDateTime      time.Time      `json:"createdDateTime"`
	LastModifiedDateTime time.Time      `json:"lastModifiedDateTime"`
	Deleted              *DeletedFacet  `json:"deleted,omitempty"`
	File                 *FileFacet     `json:"file,omitempty"`
	Folder               *FolderFacet   `json:"folder,omitempty"`
	ParentReference      *ItemReference `json:"parentReference,omitempty"`
	CTag                 string         `json:"cTag,omitempty"` // Change tag
	ETag                 string         `json:"eTag,omitempty"` // Entity tag
	DownloadURL          string         `json:"@microsoft.graph.downloadUrl,omitempty"`
}

DriveItem represents a file or folder in OneDrive.

func (*DriveItem) IsDeleted

func (d *DriveItem) IsDeleted() bool

IsDeleted returns true if the drive item has been deleted.

func (*DriveItem) IsFile

func (d *DriveItem) IsFile() bool

IsFile returns true if the drive item is a file.

func (*DriveItem) IsFolder

func (d *DriveItem) IsFolder() bool

IsFolder returns true if the drive item is a folder.

type DriveItemsResponse

type DriveItemsResponse struct {
	Value    []DriveItem `json:"value"`
	NextLink string      `json:"@odata.nextLink,omitempty"`
}

DriveItemsResponse represents a response when listing drive items.

type ErrorDetail

type ErrorDetail struct {
	Code       string `json:"code"`
	Message    string `json:"message"`
	InnerError *struct {
		Code    string `json:"code,omitempty"`
		Message string `json:"message,omitempty"`
	} `json:"innerError,omitempty"`
}

ErrorDetail contains error details.

type ErrorResponse

type ErrorResponse struct {
	Error *ErrorDetail `json:"error,omitempty"`
}

ErrorResponse represents a Microsoft Graph API error.

type FileFacet

type FileFacet struct {
	MimeType string      `json:"mimeType,omitempty"`
	Hashes   *HashesType `json:"hashes,omitempty"`
}

FileFacet represents file-specific metadata.

type FolderFacet

type FolderFacet struct {
	ChildCount int `json:"childCount,omitempty"`
}

FolderFacet represents folder-specific metadata.

type HashesType

type HashesType struct {
	QuickXorHash string `json:"quickXorHash,omitempty"`
	SHA1Hash     string `json:"sha1Hash,omitempty"`
	SHA256Hash   string `json:"sha256Hash,omitempty"`
}

HashesType contains file hashes.

type ItemReference

type ItemReference struct {
	DriveID   string `json:"driveId,omitempty"`
	DriveType string `json:"driveType,omitempty"`
	ID        string `json:"id,omitempty"`
	Name      string `json:"name,omitempty"`
	Path      string `json:"path,omitempty"`
}

ItemReference represents a reference to a parent item.

type OAuthHandler

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

OAuthHandler handles OAuth operations for Microsoft Azure AD / Microsoft Graph. This handler is shared across all Microsoft services (OneDrive, SharePoint, Teams, etc.).

func NewOAuthHandler

func NewOAuthHandler() *OAuthHandler

NewOAuthHandler creates a new Microsoft OAuth handler.

func (*OAuthHandler) BuildAuthURL

func (h *OAuthHandler) BuildAuthURL(clientID, redirectURI, state, codeChallenge string, scopes []string) string

BuildAuthURL constructs the Microsoft Azure AD OAuth authorization URL. Microsoft OAuth uses the v2.0 endpoint with PKCE support.

func (*OAuthHandler) DefaultConfig

func (h *OAuthHandler) DefaultConfig() connectors.OAuthDefaults

DefaultConfig returns Microsoft's default OAuth configuration.

func (*OAuthHandler) ExchangeCode

func (h *OAuthHandler) ExchangeCode(ctx context.Context, clientID, clientSecret, code, redirectURI, codeVerifier string) (*driven.OAuthToken, error)

ExchangeCode exchanges an authorization code for tokens. Microsoft OAuth tokens expire in 1 hour and require refresh.

func (*OAuthHandler) GetUserInfo

func (h *OAuthHandler) GetUserInfo(ctx context.Context, accessToken string) (*driven.OAuthUserInfo, error)

GetUserInfo fetches the authenticated user's information from Microsoft Graph.

func (*OAuthHandler) RefreshToken

func (h *OAuthHandler) RefreshToken(ctx context.Context, clientID, clientSecret, refreshToken string) (*driven.OAuthToken, error)

RefreshToken refreshes an expired access token. Microsoft access tokens expire in 1 hour, so refresh is essential.

type User

type User struct {
	ID                string `json:"id"`
	DisplayName       string `json:"displayName"`
	UserPrincipalName string `json:"userPrincipalName"` // Email
	Mail              string `json:"mail,omitempty"`
}

User represents a Microsoft Graph user.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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