> For the complete documentation index, see [llms.txt](https://docs.osmosworks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.osmosworks.com/api-reference/auth.md).

# Authentication

## Tenant login

Authenticates an organization admin, staff member, or customer.

* **Method:** `POST`
* **Path:** `/api/v1/auth/login?tenantSlug={tenantSlug}`
* **Authentication:** None
* **Actor:** Tenant admin, staff, or customer

### Request body

```json
{
  "email": "ada@acme.example.com",
  "password": "SecurePassword123!"
}
```

### Query parameters

| Parameter    | Required                                | Description                     |
| ------------ | --------------------------------------- | ------------------------------- |
| `tenantSlug` | Staff/customer required, admin optional | The organization's unique slug. |

### Response

```json
{
  "status": "Success",
  "message": "Login successful.",
  "traceId": "...",
  "data": {
    "tokenType": "Bearer",
    "expiresIn": 3600,
    "actorType": "TENANT_ADMIN",
    "principal": {
      "id": "a1b2c3d4-...",
      "email": "ada@acme.example.com",
      "name": "Ada Admin",
      "role": "SUPER_ADMIN",
      "permissions": []
    },
    "tenant": {
      "id": "b2c3d4e5-...",
      "slug": "acme-services",
      "name": "Acme Services"
    },
    "session": {
      "accessToken": "eyJ...",
      "refreshToken": "eyJ...",
      "expiresIn": 3600,
      "permissions": []
    }
  }
}
```

The response also sets `osmos_access_token` and `osmos_refresh_token` cookies.

### Error cases

| HTTP status | Error                                                                  | Cause                  |
| ----------- | ---------------------------------------------------------------------- | ---------------------- |
| 401         | `Invalid email or password.`                                           | Bad credentials.       |
| 403         | `Please complete your organization workspace setup before signing in.` | Incomplete onboarding. |
| 404         | `Organization not found.`                                              | Unknown tenant slug.   |
| 403         | `Organization account is suspended.`                                   | Tenant suspended.      |
| 403         | `Your account has been suspended.`                                     | Principal suspended.   |

## Platform login

Authenticates a platform user.

* **Method:** `POST`
* **Path:** `/api/v1/platform/auth/login`
* **Authentication:** None
* **Actor:** Platform user

### Request body

```json
{
  "email": "admin@osmos.example.com",
  "password": "PlatformPassword123!"
}
```

### Response

Same shape as tenant login, without a tenant block.

## Exchange session handoff

Exchanges a short-lived handoff code for access and refresh tokens.

* **Method:** `POST`
* **Path:** `/api/v1/auth/session/exchange`
* **Authentication:** None

### Request body

```json
{
  "code": "HO-XXXXXX",
  "tenantSlug": "acme-services"
}
```

### Response

Returns `SessionCredentials` with `accessToken`, `refreshToken`, and `expiresIn`. Cookies are also set.

## Refresh session

Rotates the refresh token into a new access token.

* **Method:** `POST`
* **Path:** `/api/v1/auth/session/refresh`
* **Authentication:** Refresh token cookie or body

### Request body (optional)

```json
{
  "refreshToken": "eyJ..."
}
```

## Logout

Revokes the refresh token and clears session cookies.

* **Method:** `POST`
* **Path:** `/api/v1/auth/session/logout`
* **Authentication:** Refresh token cookie or body

## Password recovery

### Request reset

* **Method:** `POST`
* **Path:** `/api/v1/auth/password-recovery/forgot-password`
* **Authentication:** None

```json
{
  "email": "ada@acme.example.com"
}
```

Response:

```json
{
  "status": "Success",
  "message": "If an active account matches those details, a password reset link has been sent."
}
```

### Reset password

* **Method:** `POST`
* **Path:** `/api/v1/auth/password-recovery/reset-password`
* **Authentication:** None

```json
{
  "token": "reset-token",
  "password": "NewSecurePassword123!",
  "confirmPassword": "NewSecurePassword123!"
}
```

Platform users use `/api/v1/platform/auth/password-recovery/forgot-password` and `/api/v1/platform/auth/password-recovery/reset-password`.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.osmosworks.com/api-reference/auth.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
