# Rolin auth.md

How an AI agent gets permission to act on a Rolin account. Rolin is an OAuth 2.1 authorization server and resource server; there is no API key to copy.

## Audience

Agents and MCP clients acting for one Rolin user: a driver on their own account (scope `driver`) or a Rolin staff member operating the service (scope `admin`, admin accounts only).

## Discover

- Protected resource metadata (RFC 9728): `https://rolin.com.co/.well-known/oauth-protected-resource`, and per server `https://rolin.com.co/.well-known/oauth-protected-resource/mcp` and `https://rolin.com.co/.well-known/oauth-protected-resource/admin/mcp`.
- Authorization server metadata (RFC 8414): `https://rolin.com.co/.well-known/oauth-authorization-server`.
- Unauthenticated calls to `/mcp`, `/admin/mcp` and `/a2a` answer `401` with `WWW-Authenticate: Bearer resource_metadata="..."` and the scope they need.

## Pick a method

Rolin supports one method: **OAuth 2.1 authorization code with PKCE**, with the user approving in their browser. There is no anonymous or headless registration: every grant is tied to a person who signed in and clicked Allow.

| | |
|---|---|
| Grant types | `authorization_code`, `refresh_token` |
| PKCE | required, `S256` |
| Client authentication | `none` (public clients), `client_secret_basic`, `client_secret_post` |
| Scopes | `driver`, `admin` |
| Access token lifetime | 1 hour, opaque bearer token |
| Refresh tokens | rotated on every use |

## Register

`POST https://rolin.com.co/oauth/register` (RFC 7591 dynamic client registration), JSON body:

```json
{
  "client_name": "My agent",
  "redirect_uris": ["http://127.0.0.1:33418/callback"],
  "token_endpoint_auth_method": "none",
  "grant_types": ["authorization_code", "refresh_token"],
  "response_types": ["code"],
  "scope": "driver"
}
```

Redirect URIs must be `https`, a loopback address (`localhost`, `127.0.0.1`, `[::1]`, any port), or a custom app scheme. The response holds your `client_id` (and `client_secret` for confidential clients). Registration does not grant access to anything by itself.

## Authorize

Send the user to:

```
https://rolin.com.co/oauth/authorize?response_type=code&client_id=CLIENT_ID&redirect_uri=REDIRECT_URI
  &scope=driver&state=STATE&code_challenge=CHALLENGE&code_challenge_method=S256
```

They sign in to Rolin if needed and see a consent screen naming your client and the scope. Allow redirects back with `code`; Deny with `error=access_denied`. Asking for `admin` on a non-admin account is refused.

## Exchange

```
POST https://rolin.com.co/oauth/token
grant_type=authorization_code&code=CODE&redirect_uri=REDIRECT_URI&client_id=CLIENT_ID&code_verifier=VERIFIER
```

Refresh with `grant_type=refresh_token&refresh_token=...&client_id=CLIENT_ID`.

## Use

Send `Authorization: Bearer ACCESS_TOKEN` to:

- `https://rolin.com.co/mcp`: driver MCP server (scope `driver`).
- `https://rolin.com.co/admin/mcp`: admin MCP server (scope `admin`).
- `https://rolin.com.co/a2a`: A2A agent (scope `driver`).

## Errors

- `401 invalid_token`: missing, expired or revoked token. Refresh, or authorize again.
- `403 insufficient_scope`: the token lacks the scope in `WWW-Authenticate`; authorize again asking for it. On `/admin/mcp` it also means the account is not an admin.
- Tool failures come back as MCP tool results with `isError: true` and a message you can show the user.

## Revocation

- Agent side: `POST https://rolin.com.co/oauth/revoke` with `token=...&client_id=...` (RFC 7009).
- User side: Profile → Connected agents in the app signs an agent out of their account at once. Archived accounts lose access immediately.
