calsync

package
v1.0.260758 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package calsync implements the OAuth2 loopback (PKCE) connect flow and event fetching for opt-in Google Calendar / Microsoft Graph sync.

There is no ttypedesk-wide OAuth client: each user configures their own Client ID (Settings → Calendar), created in their own Google Cloud Console / Azure Portal project. Shipping (and keeping secret) a single client ID/secret for public, source-available distribution isn't realistic, and Google/Microsoft's "installed app" / public-client flows are specifically designed for exactly this bring-your-own-client-ID model — no client secret is required on either side when paired with PKCE.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect

func Connect(ctx context.Context, provider Provider, clientID string, onURL func(url string), save func(token []byte) error) error

Connect runs an interactive OAuth2 loopback (PKCE) flow for provider, using the caller's own registered clientID. onURL receives the consent URL as soon as it's built, so callers can display it even where no local browser exists — the common case for this project, over SSH or headless — in addition to this function's own best-effort local browser launch. save receives the resulting token, JSON-encoded (*oauth2.Token), once the flow completes; it's the caller's job to persist it (e.g. via internal/credstore).

Types

type Provider

type Provider string

Provider identifies which calendar service an account connects to.

const (
	Google    Provider = "google"
	Microsoft Provider = "microsoft"
)

type SyncedEvent

type SyncedEvent struct {
	ID     string
	Title  string
	Start  time.Time
	End    time.Time
	AllDay bool
}

SyncedEvent is a provider-agnostic calendar event, converted from whatever shape Google/Microsoft's APIs return.

func FetchEvents

func FetchEvents(ctx context.Context, provider Provider, clientID string, from, to time.Time, loadToken func() ([]byte, error), saveToken func([]byte) error) ([]SyncedEvent, error)

FetchEvents fetches events starting in [from, to) for provider, using a previously stored token (loaded via loadToken). If the token was refreshed during the call (expired access token, valid refresh token), the refreshed token is persisted back via saveToken before returning — callers never need to re-run Connect just because a token expired.

Jump to

Keyboard shortcuts

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