#pragma once // Credentials and client wiring for Workspace, and the Workspace facade. // // Scopes: Workspace APIs refuse the cloud-platform scope; each API has its own // (see ApiSpec::scopes, full list per API in SPEC.md). `Scopes` selects the // read-only subset by default. // // Credential choice (WorkspaceAuth::from_env), first match wins: // 1. a delegation subject (option or GOOGLE_WORKSPACE_SUBJECT): the service // account key in GOOGLE_APPLICATION_CREDENTIALS impersonates that user // (domain-wide delegation). No key: GoogleError invalid. // 2. GOOGLE_ACCESS_TOKEN: a user's OAuth token, used as is (its scopes were // fixed when the user consented). // 3. GOOGLE_APPLICATION_CREDENTIALS without subject: the service account // itself (it owns no Workspace data; expect empty lists or 403). // 4. nothing: null, every call throws NotConfiguredError. #include #include #include #include #include "clients/auth.h" #include "google/client.h" #include "google/workspace/delegation.h" #include "google/workspace/services.h" namespace molo::google::workspace { class Scopes { public: // Scope URLs of the named APIs. readonly: the read-only subset; an API // without one (groupssettings) contributes its full scope. // Throws GoogleError (invalid) for an unknown API, no API, or over 40 scopes. static std::vector for_apis(const std::vector& apis, bool readonly); static std::vector all_of(const std::string& api); static std::vector readonly_of(const std::string& api); }; struct WorkspaceOptions { std::vector apis; // which APIs the token must cover bool readonly = true; Delegation delegation; // typed `sub` option; empty: env, then none }; class WorkspaceAuth { public: static std::shared_ptr from_env(const WorkspaceOptions& options); // "delegated", "user-token", "service-account" or "none": for status pages. static std::string mode_from_env(const WorkspaceOptions& options); }; // GoogleClient over HttpTransport with the credential above. std::shared_ptr make_workspace_client(const WorkspaceOptions& options); // All twenty services over one client. class Workspace { public: explicit Workspace(std::shared_ptr client); // Any API by name (see api_names()). WorkspaceApi api(const std::string& name) const { return WorkspaceApi(client_, name); } static std::vector api_names(); Gmail gmail() const { return Gmail(client_); } Drive drive() const { return Drive(client_); } Calendar calendar() const { return Calendar(client_); } Sheets sheets() const { return Sheets(client_); } Docs docs() const { return Docs(client_); } Slides slides() const { return Slides(client_); } Forms forms() const { return Forms(client_); } Tasks tasks() const { return Tasks(client_); } Chat chat() const { return Chat(client_); } Meet meet() const { return Meet(client_); } People people() const { return People(client_); } Keep keep() const { return Keep(client_); } Classroom classroom() const { return Classroom(client_); } YouTube youtube() const { return YouTube(client_); } YouTubeAnalytics youtube_analytics() const { return YouTubeAnalytics(client_); } YouTubeReporting youtube_reporting() const { return YouTubeReporting(client_); } Directory directory() const { return Directory(client_); } Reports reports() const { return Reports(client_); } GroupsSettings groups_settings() const { return GroupsSettings(client_); } Vault vault() const { return Vault(client_); } private: std::shared_ptr client_; }; } // namespace molo::google::workspace