# OAuth endpoints

> The authorization server of each project: metadata, tokens, authorization, device flow, registration, revocation and introspection.

Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service).  
Source: https://data.docs.sypnia.com/api/oauth-endpoints/

For agents: OAuth endpoints per project: GET /.well-known/oauth-authorization-server and /.well-known/openid-configuration (issuer https://<ref>.data.sypnia.com/auth/v1, endpoints, grant types, token_endpoint_auth_methods_supported [private_key_jwt, client_secret_basic, client_secret_post, none], dpop_signing_alg_values_supported [EdDSA, ES256], code_challenge_methods_supported [S256]); GET /.well-known/oauth-protected-resource; GET /.well-known/jwks.json (also /auth/v1/.well-known/jwks.json and /auth/v1/.well-known/openid-configuration); POST /auth/v1/oauth/token (client_credentials, authorization_code, refresh_token, urn:ietf:params:oauth:grant-type:device_code); GET /auth/v1/oauth/authorize; POST /auth/v1/oauth/device_authorization; POST /auth/v1/oauth/register (RFC 7591); POST /auth/v1/oauth/revoke (RFC 7009); POST /auth/v1/oauth/introspect (RFC 7662, client auth required). For the approval screens (a signed-in person): GET /auth/v1/oauth/device?user_code=, POST /auth/v1/oauth/device/approve {user_code, decision}, GET /auth/v1/oauth/flows/{id}, POST /auth/v1/oauth/authorize/decision {flow_id, decision}; the engine's own minimal pages GET /auth/v1/device and GET /auth/v1/oauth/consent. scopes_supported: data:read data:write sql:read sql:write auth:admin project:admin openid email offline_access.

## Discovery

| Endpoint                                      | Returns                                                    |
| --------------------------------------------- | ---------------------------------------------------------- |
| `GET /.well-known/oauth-authorization-server` | RFC 8414 metadata                                          |
| `GET /.well-known/openid-configuration`       | the same, for OpenID-minded clients                        |
| `GET /.well-known/oauth-protected-resource`   | RFC 9728: which authorization server protects this project |
| `GET /.well-known/jwks.json`                  | the project's public signing keys                          |

The same metadata answers at `/auth/v1/.well-known/openid-configuration` and `/.well-known/oauth-authorization-server/auth/v1`, and the keys at `/auth/v1/.well-known/jwks.json`, for clients that look for them under the issuer.

```json
{
  "issuer": "https://<ref>.data.sypnia.com/auth/v1",
  "token_endpoint": "https://<ref>.data.sypnia.com/auth/v1/oauth/token",
  "authorization_endpoint": "https://<ref>.data.sypnia.com/auth/v1/oauth/authorize",
  "device_authorization_endpoint": "https://<ref>.data.sypnia.com/auth/v1/oauth/device_authorization",
  "registration_endpoint": "https://<ref>.data.sypnia.com/auth/v1/oauth/register",
  "revocation_endpoint": "https://<ref>.data.sypnia.com/auth/v1/oauth/revoke",
  "introspection_endpoint": "https://<ref>.data.sypnia.com/auth/v1/oauth/introspect",
  "jwks_uri": "https://<ref>.data.sypnia.com/.well-known/jwks.json",
  "grant_types_supported": ["client_credentials", "authorization_code", "refresh_token", "urn:ietf:params:oauth:grant-type:device_code"],
  "token_endpoint_auth_methods_supported": ["private_key_jwt", "client_secret_basic", "client_secret_post", "none"],
  "code_challenge_methods_supported": ["S256"],
  "dpop_signing_alg_values_supported": ["EdDSA", "ES256"],
  "scopes_supported": ["data:read", "data:write", "sql:read", "sql:write", "auth:admin", "project:admin", "openid", "email", "offline_access"]
}
```

## Endpoints

| Endpoint                                   | Standard                   | Does                                                                                                                                                               |
| ------------------------------------------ | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `POST /auth/v1/oauth/token`                | RFC 6749, 7523, 8628, 9449 | issues tokens for `client_credentials`, `authorization_code` (PKCE required), `refresh_token`, `urn:ietf:params:oauth:grant-type:device_code`                      |
| `GET /auth/v1/oauth/authorize`             | RFC 6749 + PKCE            | starts an authorization code flow; the person signs in and consents                                                                                                |
| `POST /auth/v1/oauth/device_authorization` | RFC 8628                   | `{ device_code, user_code, verification_uri, verification_uri_complete, expires_in: 600, interval: 5 }`                                                            |
| `POST /auth/v1/oauth/register`             | RFC 7591                   | registers a client (public by default; confidential with an initial access token)                                                                                  |
| `POST /auth/v1/oauth/revoke`               | RFC 7009                   | revokes a refresh token (and its session) or an access token's session                                                                                             |
| `POST /auth/v1/oauth/introspect`           | RFC 7662                   | for resource servers of yours: is this token active, whose, which scopes: `{ active, sub, client_id, scope, exp, aud, cnf }`; the caller authenticates as a client |

Token response:

```json
{ "access_token": "eyJ…", "token_type": "DPoP", "expires_in": 900, "scope": "data:read", "refresh_token": "syp_rt_…" }
```

`refresh_token` is present for `authorization_code` and `device_code`, never for `client_credentials`.

Errors follow RFC 6749 and RFC 8628 ([every code](https://data.docs.sypnia.com/api/errors-and-limits#oauth)): `invalid_request`, `invalid_client`, `invalid_grant`, `unauthorized_client`, `unsupported_grant_type`, `invalid_scope`, `invalid_target`, `invalid_dpop_proof`, `use_dpop_nonce`, `authorization_pending`, `slow_down`, `access_denied`, `expired_token`.

## The approval screens

A device code and an authorization request are approved by a **signed-in person**, on a page of your app or of the console (`device_verification_uri` and `consent_url` in the [project settings](https://data.docs.sypnia.com/self-hosting/configuration#a-project)). The page calls these with the person's session; a token of a machine or an app acting for the person gets `403 person_required`.

| Endpoint                                                         | Does                                                                                                                    |
| ---------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| `GET /auth/v1/oauth/device?user_code=…`                          | what a device code asks for: `{ client_id, client_name, scopes, device_name, expires_at, expired, approved, denied }`   |
| `POST /auth/v1/oauth/device/approve` `{ user_code, decision }`   | `decision`: `approve` or `deny`; approving privileged scopes the person was not granted answers `403 scope_not_allowed` |
| `GET /auth/v1/oauth/flows/{id}`                                  | what an authorization request asks for: `{ client_name, scopes, redirect_host, resource }`                              |
| `POST /auth/v1/oauth/authorize/decision` `{ flow_id, decision }` | approves or denies it; answers `{ redirect_to }`                                                                        |
| `GET /auth/v1/device`, `GET /auth/v1/oauth/consent`              | the engine's own minimal pages for both, used when the project sets no page of its own                                  |
