# Auth endpoints

> Every endpoint under /auth/v1 and /auth/v1/admin, with what it takes and returns.

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

For agents: Endpoints: POST /auth/v1/signup {email, password?, data?, redirect_to?, captcha_token?}; POST /auth/v1/token?grant_type=password|refresh_token|pkce; POST /auth/v1/otp (alias /auth/v1/magiclink) {email, create_user?, data?, redirect_to?, captcha_token?}; POST/GET /auth/v1/verify {type, token_hash | email+token}; POST /auth/v1/recover; GET/PUT /auth/v1/user; POST /auth/v1/reauthenticate; POST /auth/v1/logout?scope=local|others|global; GET /auth/v1/sessions, DELETE /auth/v1/sessions/{id}; GET/POST /auth/v1/tokens, DELETE /auth/v1/tokens/{id} (PATs {name, scopes, resource?, expires_at?}); GET /auth/v1/authorize?provider=&redirect_to=&code_challenge=; GET /auth/v1/user/identities/authorize (link, answers {url}); DELETE /auth/v1/user/identities/{provider} (422 last_identity); GET /auth/v1/callback; GET /auth/v1/settings (providers, signup_open, require_email_confirmation, password_min_length, password_requirements, captcha, project_name, email_ready); admin with a secret key: GET/POST /auth/v1/admin/users (search, page, per_page ≤ 1000), GET/PUT/DELETE /auth/v1/admin/users/{id} (ban_duration), POST /auth/v1/admin/users/{id}/logout, POST /auth/v1/admin/invite, POST /auth/v1/admin/generate_link {type signup|invite|magiclink|recovery, email}, GET/PATCH /auth/v1/admin/settings, /auth/v1/admin/oauth/clients, POST /auth/v1/admin/oauth/registration-tokens, /auth/v1/admin/api-keys (protected, rotate-protected), POST /auth/v1/admin/keys/rotate. Session response {access_token, token_type, expires_in, expires_at, refresh_token, user}. E-mail flows answer 202 email_queued_retry when the provider failed, 409 email_provider_required without a provider.

All take the project key in `apikey`. Signed-in calls also send the user's access token.

## Sign-up and sign-in

`POST /auth/v1/signup` \[Engine, Cloud]

- `email` (string, required)
  The person's e-mail.
- `password` (string, optional)
  Optional: without it, «e-mail first».
- `data` (object, optional)
  Goes to&#x20;
  `user_metadata`
  .
- `redirect_to` (string, optional)
  Where the confirmation link returns; must be an allowed redirect URL.
- `captcha_token` (string, optional)
  Required when the project has a CAPTCHA.

**Authentication:** publishable key

Returns the user (unconfirmed), or a session if confirmation is off. Errors: `email_exists`, `email_unconfirmed`, `invalid_email`, `weak_password`, `signup_disabled`, `email_provider_disabled`, `captcha_required`, `429 rate_limited`, and `409 email_provider_required` when the sign-up needs an e-mail and the project has [no provider](https://data.docs.sypnia.com/auth/email-providers-and-templates#without-a-provider) (the same answer from `otp`, `recover`, `reauthenticate`, an e-mail change and `admin/invite`).

`POST /auth/v1/token?grant_type=password` \[Engine, Cloud]

- `email` (string, required)
  The e-mail.
- `password` (string, required)
  The password.
- `captcha_token` (string, optional)
  Required when the project has a CAPTCHA.

**Authentication:** publishable key

Errors: `invalid_credentials`, `email_not_confirmed`, `user_banned`, `captcha_required`, `429 rate_limited` (also while the account waits after repeated failures).

`POST /auth/v1/token?grant_type=refresh_token` \[Engine, Cloud]

- `refresh_token` (string, required)
  The current refresh token; a new one comes back.

**Authentication:** publishable key

Errors: `invalid_refresh_token`, `refresh_token_reused`, `session_expired`, `session_revoked`, `invalid_dpop_proof` (a refresh token bound to a key). A refresh token of an agent session is renewed at `/auth/v1/oauth/token` instead (`invalid_grant` here).

`POST /auth/v1/token?grant_type=pkce` \[Engine, Cloud]

- `auth_code` (string, required)
  The&#x20;
  `code`
  &#x20;from the provider redirect.
- `code_verifier` (string, required)
  The verifier the client kept.

**Authentication:** publishable key

A session:

```json
{ "access_token": "eyJ…", "token_type": "bearer", "expires_in": 3600, "expires_at": 1795000000,
  "refresh_token": "syp_rt_…", "user": { "id": "7c0e…", "email": "ana@example.com", "email_confirmed_at": "…", "user_metadata": {} } }
```

## Links, codes and recovery

| Endpoint                                                                           | Does                                                                                                                   |
| ---------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
| `POST /auth/v1/otp` `{ email, create_user?, data?, redirect_to?, captcha_token? }` | e-mails a sign-in link and code; `create_user` (default `true`) creates the user when the e-mail is new                |
| `POST /auth/v1/magiclink`                                                          | the same as `/auth/v1/otp`                                                                                             |
| `POST /auth/v1/verify` `{ type, token_hash }` or `{ type, email, token }`          | checks a link or code; returns a session. `type`: `signup`, `magiclink`, `recovery`, `invite`, `email_change`, `email` |
| `GET /auth/v1/verify?token_hash=…&type=…&redirect_to=…`                            | the same from an e-mail link; `303` to `redirect_to#access_token=…`                                                    |
| `POST /auth/v1/recover` `{ email, redirect_to?, captcha_token? }`                  | e-mails a recovery link; always `200`                                                                                  |
| `POST /auth/v1/reauthenticate`                                                     | e-mails a code for a sensitive change, valid 10 minutes; pass it as `nonce`                                            |

The flows that send an e-mail answer `{"status": "sent"}`, or `202` with `{"status": "email_queued_retry"}` when the provider failed and the e-mail is being retried. Without a provider they answer `409 email_provider_required`.

## The signed-in user

| Endpoint                                                                                                                | Does                                                                                |
| ----------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| `GET /auth/v1/user`                                                                                                     | the user, fresh                                                                     |
| `PUT /auth/v1/user` `{ password?, email?, data?, nonce? }`                                                              | changes; password needs a recent sign-in or `nonce`                                 |
| `POST /auth/v1/logout?scope=local\|others\|global`                                                                      | ends sessions                                                                       |
| `GET /auth/v1/sessions`, `DELETE /auth/v1/sessions/{id}`                                                                | the person's devices                                                                |
| `GET /auth/v1/tokens`, `POST /auth/v1/tokens` `{ name, scopes, resource?, expires_at? }`, `DELETE /auth/v1/tokens/{id}` | personal access tokens; the token comes back once; `expires_at: null` never expires |

Changing the account (password, e-mail, PATs, sessions, linked identities) needs the person's own session: a PAT or an app acting for them gets `403 person_required`.

## Providers

| Endpoint                                                                                                   | Does                                                                                                                                                                                     |
| ---------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `GET /auth/v1/authorize?provider=google\|github&redirect_to=…&code_challenge=…&code_challenge_method=S256` | starts a provider sign-in                                                                                                                                                                |
| `GET /auth/v1/user/identities/authorize?provider=…&redirect_to=…&code_challenge=…`                         | signed in: links another provider; answers `{ url }` to open; the return gives `?code=` for `grant_type=pkce`                                                                            |
| `DELETE /auth/v1/user/identities/{provider}`                                                               | signed in: unlinks a provider; `422 last_identity` when it is the last way to sign in                                                                                                    |
| `GET /auth/v1/callback`                                                                                    | where the provider returns; redirects to your app with `?code=`                                                                                                                          |
| `GET /auth/v1/settings`                                                                                    | public: `providers` (`email`, `google`, `github`), `signup_open`, `require_email_confirmation`, `password_min_length`, `password_requirements`, `captcha`, `project_name`, `email_ready` |

## Admin (secret key)

| Endpoint                                                                         | Does                                                                                                                                                                                                        |
| -------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `GET /auth/v1/admin/users?search=&page=&per_page=`                               | list and search: `{ users, total }`; `per_page` 50 by default, up to 1 000                                                                                                                                  |
| `POST /auth/v1/admin/users`                                                      | create (`email_confirm`, `password`, `user_metadata`, `app_metadata`)                                                                                                                                       |
| `POST /auth/v1/admin/invite` `{ email, data?, redirect_to? }`                    | creates the user and e-mails an invitation                                                                                                                                                                  |
| `GET/PUT/DELETE /auth/v1/admin/users/{id}`                                       | read, change (`email`, `password`, `email_confirm`, `user_metadata`, `app_metadata`, `ban_duration` such as `24h`, `7d` or `none`), delete                                                                  |
| `POST /auth/v1/admin/users/{id}/logout`                                          | end every session of the user                                                                                                                                                                               |
| `POST /auth/v1/admin/generate_link` `{ type, email, redirect_to? }`              | a link without sending it, for `signup`, `invite`, `magiclink` or `recovery`: `action_link`, `email_otp`, `hashed_token`, `verification_type`                                                               |
| `GET/PATCH /auth/v1/admin/settings`                                              | the project's settings ([all of them](https://data.docs.sypnia.com/self-hosting/configuration#a-project)); `GET` adds `template_defaults`, `template_variables`, `mail_state` and `mail_providers`          |
| `GET/POST/PATCH/DELETE /auth/v1/admin/oauth/clients[/{id}]`                      | OAuth clients ([client credentials](https://data.docs.sypnia.com/machines/client-credentials)); a secret is shown once                                                                                      |
| `POST /auth/v1/admin/oauth/registration-tokens` `{ name, scopes?, expires_at? }` | an initial access token `syp_iat_…` for a confidential [dynamic registration](https://data.docs.sypnia.com/api/oauth-endpoints#endpoints), shown once                                                       |
| `GET/POST/DELETE /auth/v1/admin/api-keys[/{id}]`                                 | API keys; `POST` takes `kind` (`publishable` or `secret`), `name` and `protected`; `DELETE` of a protected key answers `409 protected_key`; revoking the key you are calling with answers `400 not_allowed` |
| `POST /auth/v1/admin/api-keys/{id}/rotate-protected`                             | replaces a [protected key](https://data.docs.sypnia.com/machines/tokens-and-api-keys#protected-keys): the new key (shown once) and the old one revoked, in one transaction                                  |
| `POST /auth/v1/admin/keys/rotate`                                                | publishes a new signing key: `{ next_kid }`; it signs 24 hours later ([signing keys](https://data.docs.sypnia.com/auth/sessions-and-tokens#signing-keys))                                                   |

Every admin endpoint needs a secret key (or a `service_role` token); anything else gets `403 secret_key_required`. All error codes: [Errors and limits](https://data.docs.sypnia.com/api/errors-and-limits#auth).
