﻿<head><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4357510538660394"
     crossorigin="anonymous"></script></head># Connect Microsoft and Google

> Canonical HTML: https://screenrig.ai/docs/connections

A connection saves your project's credentials for Microsoft or Google so background integrations can run without a signed-in user. Meeting-room sources, Power BI dashboards, and SharePoint or OneDrive media sync reference a single connection instead of storing separate tenant IDs, client IDs, and secrets. Configure it once and reuse it across features.

## How connections work

- **Provider and mode.** Set `provider` to `microsoft` or `google`. Set `mode` to `own_app` (your own Microsoft Entra app or Google service account) or `screenrig_app` (screenRIG's app, approved by a Microsoft 365 administrator or Google account holder).
- **Status.** A `screenrig_app` connection starts in `pending_consent` until someone completes approval. Once valid credentials are stored, its status is `ready`. If Microsoft or Google rejects those credentials, the status changes to `error` with details in `last_error`, and returns to `ready` after the next successful sign-in. Temporary rate limits or provider outages do not change the connection's status.
- **Write-only secrets.** Client secrets, private keys, and refresh tokens are never displayed again after you save them. Reading a connection returns whether a secret is stored along with a non-sensitive hint: the last four characters of a Microsoft client secret or the email address of a Google service account.
- **Testing.** Running a test authenticates with the provider and saves the result. For Microsoft connections, the test also lists the Microsoft Graph application permissions granted to the sign-in.
- **Updating.** Updating credentials on an `own_app` connection resets its status to `ready` and clears `last_error`. A `screenrig_app` connection can only be renamed—request a new consent link to change the approving account or tenant.
- **Deleting.** Deleting a connection fails with `resource_conflict` while any data source, Power BI connection, or media sync account still uses it. Deleting a connection in screenRIG does not revoke access on the provider's side: remove screenRIG's enterprise application in Microsoft Entra or revoke the grant in Google Account settings separately.
- **Limit.** An organization can have up to 50 connections across all of its projects.

## Choose a mode: your own app vs. screenRIG's app

| Aspect | Your own app (`own_app`) | screenRIG's app (`screenrig_app`) |
| --- | --- | --- |
| Credentials you provide | Microsoft: tenant ID or domain, client ID, and client secret. Google: service account JSON key | None—screenRIG generates a one-time consent link |
| Who grants access | You, when registering the app and granting permissions | A Microsoft 365 administrator or Google account holder who opens the link |
| Scope of access | Whatever permissions you grant your app | Microsoft: permissions approved by the admin (which you can restrict further). Google: read-only access to calendars visible to the approving account |
| Power BI | Supported | Not supported—use `own_app` for Power BI |

## Microsoft

### Your own app

1. Register an application in the Microsoft Entra admin center and create a client secret (copy the secret **value**, not its ID).
2. Assign the required Microsoft Graph application permissions from the table below and grant admin consent.
3. Create the connection with:
   - `config.tenant_id`: your directory ID or primary domain (`common`, `organizations`, and `consumers` are rejected).
   - `config.client_id`: the application (client) ID.
   - `secret`: the client secret value.

### screenRIG's app (admin consent)

Create a connection with `mode` set to `screenrig_app` and omit `config` and `secret`. The response includes `consent_url`, a one-time link valid for 24 hours. Send this link only to a Microsoft 365 administrator—it authorizes that consent directly.

1. The administrator opens the link and approves screenRIG's app for the tenant.
2. Microsoft redirects back to screenRIG and prompts the administrator to sign in to the tenant. The connection records the verified tenant from that sign-in rather than trusting a tenant claimed in a request.
3. screenRIG authenticates once using the granted permissions, and the connection moves to `ready`.

**Link lifecycle and errors:**

- Each consent link is single-use. Generating a new link, completing consent, or deleting the connection invalidates any earlier link. You can request a new link at any time to recover a connection in `error` or switch to another tenant.
- If the administrator declines or sign-in fails, the connection records `consent_denied` or `consent_failed` (including Microsoft's `AADSTS` code) and keeps its pending consent so the same link can be retried.
- A declined re-consent never disrupts a connection that is already `ready`.
- If the tenant removes screenRIG's app, the connection reports `consent_revoked`—have an administrator approve a new consent link to restore it.

Approval is per tenant, and a tenant connects to one screenRIG organization. The person who signs in is a Global Administrator or Privileged Role Administrator of the tenant; anyone else is refused with `consent_failed`. Every project of that organization connects the tenant the same way, and another organization connects it with its own Microsoft Entra app. Narrow what the app can read, as below. Deleting the enterprise application in Microsoft Entra ends the access of every project.

### Required Microsoft Graph permissions

| Use case | Permission | Notes |
| --- | --- | --- |
| Room calendars | `Calendars.Read` | Restrict access to a mail-enabled security group of room mailboxes with `New-ApplicationAccessPolicy -AccessRight RestrictAccess` |
| Room count (optional) | `Place.Read.All` | Allows a source test to count rooms listed in your organization |
| SharePoint and OneDrive media sync | `Sites.Selected` | Grant `read` access per site (`POST /v1.0/sites/{site-id}/permissions`). `Files.Read.All` and `Sites.Read.All` grant tenant-wide access and are not requested |
| Power BI | None for Microsoft Graph | Controlled by Power BI tenant settings and workspace membership |

Testing a connection lists which of these permissions the sign-in holds. The test warns if only `Sites.Selected` is granted (because each SharePoint site still requires an individual grant) and fails if none of these permissions are present.

## Google

### Your own app

1. Create a service account in Google Cloud, enable the Google Calendar API, and download its JSON key (up to 16 KiB).
2. Pass the entire JSON key file as `secret` when creating the connection; screenRIG validates the file on save.
3. Grant calendar access in one of two ways:
   - Share each room calendar directly with the service account's email address, or
   - Enable domain-wide delegation for the service account in the Google Admin console with the scope `https://www.googleapis.com/auth/calendar.events.readonly`, and set `subject` on the data source.

### screenRIG's app

The consent link opens Google's consent screen for the account holder to grant read-only calendar access (`calendar.events.readonly`, plus `openid` and `email` so screenRIG records which account approved). Unchecking the calendar permission causes consent to fail.

Data sources using this connection can read only the calendars visible to the approving account, so ensure that account has access to every room calendar you configure. Sources using a `screenrig_app` connection cannot set `subject`. If Google stops honoring the grant, the connection reports `reconnect_required`—request a new consent link to reconnect.

## Use a connection

- **Meeting-room sources.** Set `connection_id` on a `microsoft365` or `google_calendar` [data source](https://screenrig.ai/docs/sources.md#meeting-rooms) instead of inline credentials (`tenant`, `client_id`, and `client_secret`, or `service_account_key`). Both `own_app` and `screenrig_app` modes are supported. Inline credentials still work, but you cannot combine them with `connection_id`.
- **SharePoint and OneDrive media sync.** Pass `connection_id` on a Microsoft 365 sync account instead of `tenant_id`, `client_id`, and `secret`.
- **Power BI.** Pass the `connection_id` of a Microsoft `own_app` connection instead of separate tenant, client ID, and secret fields. Because Microsoft does not support cross-tenant apps generating embed tokens for a customer tenant, `screenrig_app` connections are rejected for Power BI. A Power BI administrator must still enable service principal access and add the app to each target workspace.

If a referenced connection is missing, still awaiting approval, or belongs to the wrong provider, the data source reports `config_invalid`. If Microsoft or Google rejects sign-in, the source reports `auth_failed` and the connection status changes to `error`.

## Create and manage connections

You can manage connections on the dashboard's **Connections** page (grouped into **Needs attention**, **Waiting for consent**, and **Ready**), with the CLI, or via `POST /api/connections`.

### CLI

```sh
screenrig connection create microsoft --mode own_app --tenant-id contoso.com --client-id 0b1d2f3a-4c5e-4f60-8a7b-9c0d1e2f3a4b --secret-file secret.txt
screenrig connection create google --mode screenrig_app --name "Campus rooms"
screenrig connection test pcn_ID
screenrig connection connect pcn_ID
```

`--secret-file` and `--service-account-key-file` read secrets from a file or from standard input (`-`), never from a command-line argument.

Other CLI commands:

- `connection list` and `connection show`: inspect saved connections.
- `connection update`: rename a connection or replace `own_app` credentials.
- `connection test`: sign in and record the result.
- `connection connect`: generate a new consent link.
- `connection delete`: remove an unused connection.

### API

Create a Microsoft `own_app` connection (keep secrets in a request file rather than on the command line):

```json
{
  "provider": "microsoft",
  "mode": "own_app",
  "name": "Contoso rooms",
  "config": {"tenant_id": "contoso.com", "client_id": "CLIENT_ID"},
  "secret": "CLIENT_SECRET_VALUE"
}
```

Create a Google `screenrig_app` connection (no `config` or `secret` required):

```json
{"provider": "google", "mode": "screenrig_app", "name": "Campus rooms"}
```

The `screenrig_app` response returns `consent_url` and `consent_expires_at`—send `consent_url` to the approving administrator or account holder. Use `POST /api/connections/ID/connect` to issue a new consent link and `POST /api/connections/ID/test` to test credentials and save the result.

### Common errors

- [`connection_app_not_configured`](https://screenrig.ai/problems/connection-app-not-configured): this server has no screenRIG app configured for that provider. Create the connection in `own_app` mode instead.
- [`connection_limit_reached`](https://screenrig.ai/problems/connection-limit-reached): the organization has reached its limit of 50 connections. Delete an unused connection or reuse an existing one.

## Related

- [Data sources](https://screenrig.ai/docs/sources.md): meeting-room sources that reference a connection.
- [API reference](https://screenrig.ai/docs/api#group-connections): complete endpoint reference for connections.
- [Single sign-on](https://screenrig.ai/docs/single-sign-on.md): how users sign in to screenRIG (unlike connections, which run without a signed-in user).
