---
title: "Get an access token (password or refresh_token grant)"
---

`POST /api/token`

Exchanges SaaSify user credentials for an opaque bearer token using the OAuth2 resource-owner **password** grant, or refreshes an existing token with the **refresh_token** grant. The body is `application/x-www-form-urlencoded`. There is no client id/secret. Send the optional `TenantCode` header to select a tenant when the user belongs to more than one. The returned token is valid for 1440 minutes and is sent on every other call as `Authorization: Bearer <token>`. Do not send the `X-SaaSify-Client` header from server-to-server integrations (it switches the token into browser cookies).

## Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `TenantCode` | header | string |  | Optional tenant code. Sets the default tenant context for the issued token. |

## Request body

Required. Content type: `application/x-www-form-urlencoded`.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `password` | string |  | SaaSify user password (password grant). |
| `username` | string |  | SaaSify user email (password grant). |
| `grant_type` | string: `password`, `refresh_token` | yes | Grant type. |
| `onBehalfOf` | string |  | Optional impersonation claim (username to act on behalf of). |
| `refresh_token` | string |  | A previously issued refresh token (refresh_token grant). |

## Responses

| Status | Description |
| --- | --- |
| `200` | A bearer token. This endpoint returns the raw OAuth token object, not the standard envelope. |
| `400` | Invalid grant. Standard OAuth error body. |
