# OAuth & connected apps

Source: https://mroffice.ai/en/developers/oauth

Sign people in to your app with their MR Office account: OAuth 2.1 with PKCE, client ID metadata documents, dynamic registration, scopes and token introspection.

## Overview

MR Office is an OAuth 2.1 authorization server for apps that act as a person: AI apps, the MCP server, desktop and command-line tools. Public clients only, with PKCE (S256); no client secrets, since a secret shipped inside an app protects nothing.

- Discovery: RFC 8414 metadata at /.well-known/oauth-authorization-server and RFC 9728 at /.well-known/oauth-protected-resource/api (the API's resource, https://mroffice.ai/api).
- Clients: a client ID metadata document (your client_id is an https URL serving your app's JSON) or dynamic registration (RFC 7591).
- Redirect URIs: https, loopback http on any port (RFC 8252), or your app's private-use scheme.
- Tokens are opaque. Access tokens live an hour; refresh tokens 30 days and rotate on every use; presenting a spent refresh token revokes the whole grant.
- Every token is bound to the resource it was asked for (RFC 8707): MR Office's API (https://mroffice.ai/api) or its first-party MCP endpoints.

```bash
curl https://mroffice.ai/.well-known/oauth-authorization-server
curl https://mroffice.ai/.well-known/oauth-protected-resource/api
```

## Scopes

| Scope | Lets your app |
| --- | --- |
| office.convert | Read Word, Excel and PowerPoint files into MR Office's editors and write them back as Office files, as the person. Nothing is stored in their account. The default. |
| account.read | See the person's name and e-mail address (GET /api/v1/oauth/userinfo). |
| embed.apps | For MR Office's own tools only (npx mroffice-embed init): list and create the person's embed apps and receive a new app's keys. Other apps asking for it are refused. |
| office.edit | For MR Office's own tools only (the VS Code extension, the Obsidian plugin): open the person's files in MR Office's editors and save their changes back; a file is kept in their account while it is open. Other apps asking for it are refused. |

## Authorization code with PKCE

```bash
# 1. send the person to the consent page (PKCE, S256)
https://mroffice.ai/api/v1/oauth/authorize
  ?response_type=code
  &client_id=https://your-app.example/oauth/client.json
  &redirect_uri=http://127.0.0.1:53682/callback
  &scope=office.convert%20account.read
  &code_challenge=<BASE64URL(SHA256(verifier))>
  &code_challenge_method=S256
  &state=<random>
  &resource=https://mroffice.ai/api

# 2. exchange the code
curl -X POST https://mroffice.ai/api/v1/oauth/token \
  -d grant_type=authorization_code -d code=<code> \
  -d redirect_uri=http://127.0.0.1:53682/callback \
  -d client_id=https://your-app.example/oauth/client.json \
  -d code_verifier=<verifier>
```

A client ID metadata document (served at your client_id URL):

```json
{
  "client_id": "https://your-app.example/oauth/client.json",
  "client_name": "Your App",
  "client_uri": "https://your-app.example",
  "redirect_uris": ["http://127.0.0.1/callback", "yourapp://oauth/callback"],
  "grant_types": ["authorization_code", "refresh_token"],
  "token_endpoint_auth_method": "none"
}
```

## Checking a token

A resource server (your own MCP server, for example) checks a caller's token on each request with token-info: it describes only the presented token, to its own bearer, whatever its scope.

```bash
curl https://mroffice.ai/api/v1/oauth/token-info \
  -H "Authorization: Bearer mro_at_…"
# → { "active": true, "token_type": "Bearer", "scope": "office.convert", "sub": "…",
#     "aud": "https://mroffice.ai/api", "client_id": "…", "iat": 1795100000, "exp": 1795103600 }

curl https://mroffice.ai/api/v1/oauth/userinfo \
  -H "Authorization: Bearer mro_at_…"      # needs account.read
# → { "sub": "…", "email": "alex@example.com", "name": "Alex" }
```

## Connected apps

People see every app they allowed in MR Office's settings, with its scopes and when it was last used, and can disconnect it: disconnecting revokes every grant and token they hold for it. Signing out everywhere ends OAuth tokens too. A registered client nobody authorized is deleted after 7 days; an authorized one 30 days after its last use, once no grant of it is live.
