> ## Documentation Index
> Fetch the complete documentation index at: https://docs.prisme.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Connector authorizations upgrade

> Move the connectors' stored refresh tokens and grant the installed connectors their roles when upgrading to app authorizations.

From the release that introduces [app authorizations](https://docs.prisme.ai/products/ai-builder/integrations.md#granting-what-an-app-asks-for), an installed app reaches its own secrets only through the roles the workspace installing it grants. This changes how the per-user OAuth connectors store and replay their members' refresh tokens, and it does not happen by itself on an existing platform. Two scripts do it for every workspace at once.

This page is for the platform administrator who upgrades a Prisme.ai platform, SaaS or self-hosted. When it is done, every installed connector is granted its roles, and the scheduled synchronizations of its members work as before the upgrade.

> [!WARNING]
>
> **This is a breaking change.** Until the steps below are done, a connector installed in a workspace answers `Unknown role` on its scheduled synchronizations, and its members cannot store a connection for them. Plan the upgrade in one maintenance window and run the steps in order.

## Connectors concerned

Confluence, Figma, GitLab, Google Workspace, HubSpot, Jira, Microsoft Teams, Monday.com, OneNote, Outlook, Power BI, Salesforce and SharePoint.

## Before you start

You need:

* **A platform super admin access token.** It lists every workspace and manages the security of each. Keep it in an environment variable, never in a file you share.
* **The URL of the database holding the workspace secrets.** It is the permissions storage, configured by `PERMISSIONS_STORAGE_DRIVER` and `PERMISSIONS_STORAGE_HOST` (see [Environment variables](https://docs.prisme.ai/self-hosting/kubernetes/environment-variables.md)). The script only renames secrets and never reads their values.
* **Node.js 20 or later**, on a machine that reaches the API and that database.
* **The scripts of the release.** They are in the `scripts/` folder of the `prismeai-workspaces` sources of the release you upgrade to: `grant-app-authorizations.mjs` and `migrate-secret-app-namespace.mjs`. Run them from the root of those sources, which holds the `workspaces/` folder they read. If you do not have access to these sources, ask Prisme.ai support for the scripts of your release.

Install their dependencies once, from that root:

```bash theme={null}
npm ci
npm i --no-save pg        # PostgreSQL permissions storage
# or: npm i --no-save mongodb   # MongoDB permissions storage
```

Then set the variables the scripts read:

```bash theme={null}
export PRISME_API_BASE="https://api.<your-domain>/v2"
export PRISME_ACCESS_TOKEN="<super admin access token>"
export SECRETS_DB_URL="<permissions storage URL>"
# MongoDB only: the database name, if the URL does not carry it
# export SECRETS_DB_NAME="<database>"
```

Both scripts only simulate by default: they print what they would do and change nothing. Add `--apply` to make the change. Each can be run again: what is already done is skipped.

## Upgrade

**1. Deploy the platform services**

Bump the services to the target release and deploy them, as in [Updates → Upgrade the platform services](https://docs.prisme.ai/self-hosting/operations/updates.md#1-upgrade-the-platform-services). Do not update the products yet.

**2. List the installed connectors**

```bash theme={null}
node scripts/grant-app-authorizations.mjs --list-instances instances.json
```

The script writes every installed instance of the connectors above to `instances.json` and ends with the number of workspaces read and of errors. Rerun it if it reports errors. Both scripts take this file.

**3. Move the stored refresh tokens**

Simulate first:

```bash theme={null}
node scripts/migrate-secret-app-namespace.mjs --instances instances.json --driver postgres
```

Use `--driver mongo` for a MongoDB permissions storage. Each `WOULD MOVE` line is a token that will be renamed, and the last line gives the totals. When they match what you expect, run the same command with `--apply`.

**4. Update the products**

Pull the products from the Platform workspace, as in [Updates → Update the products](https://docs.prisme.ai/self-hosting/operations/updates.md#2-update-the-products). This publishes the new versions of the connectors, which declare the roles they need.

**5. Grant the installed connectors their roles**

Simulate first:

```bash theme={null}
node scripts/grant-app-authorizations.mjs --instances instances.json
```

Each `WOULD GRANT` line is a role an installed connector will be granted. Run the same command with `--apply`. The script grants each instance what an owner would grant from **Imports**, and nothing else.

**6. Run the token move a second time**

```bash theme={null}
node scripts/migrate-secret-app-namespace.mjs --instances instances.json --driver postgres
```

It should find nothing to move. If it lists tokens, run it with `--apply`.

## Check the result

* Run the grant simulation again: it should end with `0 to grant`.
* In **Builder**, open a workspace that installs one of these connectors, then **Imports**: the connector is no longer shown as pending.
* A member connected to one of these connectors sees their scheduled synchronizations run again.

## What the scripts leave aside

Each script prints the instances or tokens it does not change, with a reason. Nothing is changed for them.

| Reason | Meaning | What to do |
| - | - | - |
| `differs_from_repo` | The published version of the connector asks for other roles than the scripts expect. | Check that the products were updated to the same release as the scripts, then run the grant again. |
| `modified_by_hand` | The workspace already holds one of these roles, with other rules. | An owner reviews it from **Imports** and confirms the replacement. |
| `other_app_pending` | Another app of the same instance also waits for a grant. | An owner grants it from **Imports**, which covers both. |
| `refused_rules`, `unresolved_apps`, `source_not_found` | The platform could not build or read the request of this instance. | An owner opens it from **Imports** to see why. |
| `cannot_grant`, `status_403` | The token cannot manage the security of this workspace. | Use a super admin access token. |
| `no_matching_instance`, `ambiguous` | A token whose connector is not, or not uniquely, installed in its workspace. | It is left under its former name and is not used. A member reconnecting stores a new one. |
| `already_moved` | The member already reconnected after the upgrade. | Nothing: the token stored after the upgrade is the one used. |

## If a step was missed

* **A member connected between the product update and the grant.** Their connection works for what they do themselves, but no token was stored for the scheduled synchronizations. They connect again once the grant is done.
* **A workspace installs one of these connectors after the upgrade.** An owner grants it from **Imports** right after the installation, as for any app that asks for authorizations.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.