---
type: api
title: Authenticate SAML
description: Submit a SAML response message to Elasticsearch for consumption.
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/operation/operation-security-saml-authenticate
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/operation/operation-security-saml-authenticate
products:
  - Elasticsearch
---

# Authenticate SAML

Availability: 7.5+

## Paths

- `POST` `/_security/saml/authenticate`

- [Api key auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/authentication#apikeyauth)
- [Basic auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/authentication#basicauth)
- [Bearer auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/authentication#bearerauth)

## Description

Submit a SAML response message to Elasticsearch for consumption.

NOTE: This API is intended for use by custom web applications other than Kibana.
If you are using Kibana, refer to the documentation for configuring SAML single-sign-on on the Elastic Stack.

The SAML message that is submitted can be:

* A response to a SAML authentication request that was previously created using the SAML prepare authentication API.
* An unsolicited SAML message in the case of an IdP-initiated single sign-on (SSO) flow.

In either case, the SAML message needs to be a base64 encoded XML document with a root element of `<Response>`.

After successful validation, Elasticsearch responds with an Elasticsearch internal access token and refresh token that can be subsequently used for authentication.
This API endpoint essentially exchanges SAML responses that indicate successful authentication in the IdP for Elasticsearch access and refresh tokens, which can be used for authentication against Elasticsearch.

[More about SAML authentication](https://www.elastic.co/docs/deploy-manage/users-roles/cluster-or-deployment-auth/saml)

## Request Body

`application/json`

- `content` (string) — required
  The SAML response as it was sent by the user's browser, usually a Base64 encoded XML document.
- `ids` (string Ids) — required
  A JSON array with all the valid SAML Request Ids that the caller of the API has for the current user.
- `realm` (string) — optional
  The name of the realm that should authenticate the SAML response. Useful in cases where many SAML realms are defined.

## Response

`application/json`

- `access_token` (string)
  The access token that was generated by Elasticsearch.
- `username` (string)
  The authenticated user's name.
- `expires_in` (number)
  The amount of time (in seconds) left until the token expires.
- `refresh_token` (string)
  The refresh token that was generated by Elasticsearch.
- `realm` (string)
  The name of the realm where the user was authenticated.
- `in_response_to` (string)
  The id of the request that initiated the authentication process.
## Code Examples

#### Console

```console
POST /_security/saml/authenticate
{
  "content" : "PHNhbWxwOlJlc3BvbnNlIHhtbG5zOnNhbWxwPSJ1cm46b2FzaXM6bmFtZXM6dGM6U0FNTDoyLjA6cHJvdG9jb2wiIHhtbG5zOnNhbWw9InVybjpvYXNpczpuYW1lczp0YzpTQU1MOjIuMD.....",
  "ids" : ["4fee3b046395c4e751011e97f8900b5273d56685"]
}
```

#### JavaScript

```javascript
const response = await client.security.samlAuthenticate({
  content:
    "PHNhbWxwOlJlc3BvbnNlIHhtbG5zOnNhbWxwPSJ1cm46b2FzaXM6bmFtZXM6dGM6U0FNTDoyLjA6cHJvdG9jb2wiIHhtbG5zOnNhbWw9InVybjpvYXNpczpuYW1lczp0YzpTQU1MOjIuMD.....",
  ids: ["4fee3b046395c4e751011e97f8900b5273d56685"],
});
```

#### Python

```python
resp = client.security.saml_authenticate(
    content="PHNhbWxwOlJlc3BvbnNlIHhtbG5zOnNhbWxwPSJ1cm46b2FzaXM6bmFtZXM6dGM6U0FNTDoyLjA6cHJvdG9jb2wiIHhtbG5zOnNhbWw9InVybjpvYXNpczpuYW1lczp0YzpTQU1MOjIuMD.....",
    ids=[
        "4fee3b046395c4e751011e97f8900b5273d56685"
    ],
)
```

#### curl

```curl
curl -X POST "$ELASTICSEARCH_URL/_security/saml/authenticate" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "PHNhbWxwOlJlc3BvbnNlIHhtbG5zOnNhbWxwPSJ1cm46b2FzaXM6bmFtZXM6dGM6U0FNTDoyLjA6cHJvdG9jb2wiIHhtbG5zOnNhbWw9InVybjpvYXNpczpuYW1lczp0YzpTQU1MOjIuMD.....",
    "ids": [
      "4fee3b046395c4e751011e97f8900b5273d56685"
    ]
  }'
```

#### Java

```java
client.security().samlAuthenticate(s -> s
    .content("PHNhbWxwOlJlc3BvbnNlIHhtbG5zOnNhbWxwPSJ1cm46b2FzaXM6bmFtZXM6dGM6U0FNTDoyLjA6cHJvdG9jb2wiIHhtbG5zOnNhbWw9InVybjpvYXNpczpuYW1lczp0YzpTQU1MOjIuMD.....")
    .ids("4fee3b046395c4e751011e97f8900b5273d56685")
);
```

#### C#

```c#
var response = await client.Security
    .SamlAuthenticateAsync(d1 => d1
        .Content("PHNhbWxwOlJlc3BvbnNlIHhtbG5zOnNhbWxwPSJ1cm46b2FzaXM6bmFtZXM6dGM6U0FNTDoyLjA6cHJvdG9jb2wiIHhtbG5zOnNhbWw9InVybjpvYXNpczpuYW1lczp0YzpTQU1MOjIuMD.....")
        .Ids(new[] { "4fee3b046395c4e751011e97f8900b5273d56685" })
    );
```

#### PHP

```php
$resp = $client->security()->samlAuthenticate([
    "body" => [
        "content" => "PHNhbWxwOlJlc3BvbnNlIHhtbG5zOnNhbWxwPSJ1cm46b2FzaXM6bmFtZXM6dGM6U0FNTDoyLjA6cHJvdG9jb2wiIHhtbG5zOnNhbWw9InVybjpvYXNpczpuYW1lczp0YzpTQU1MOjIuMD.....",
        "ids" => array(
            "4fee3b046395c4e751011e97f8900b5273d56685",
        ),
    ],
]);
```

#### Ruby

```ruby
response = client.security.saml_authenticate(
  body: {
    "content": "PHNhbWxwOlJlc3BvbnNlIHhtbG5zOnNhbWxwPSJ1cm46b2FzaXM6bmFtZXM6dGM6U0FNTDoyLjA6cHJvdG9jb2wiIHhtbG5zOnNhbWw9InVybjpvYXNpczpuYW1lczp0YzpTQU1MOjIuMD.....",
    "ids": [
      "4fee3b046395c4e751011e97f8900b5273d56685"
    ]
  }
)
```

## Response Examples

#### Saml authenticate response example1

A successful response from `POST /_security/saml/authenticate`.

```json
{
  "access_token" : "46ToAxZVaXVVZTVKOVF5YU04ZFJVUDVSZlV3",
  "username" : "Bearer",
  "expires_in" : 1200,
  "refresh_token": "mJdXLtmvTUSpoLwMvdBt_w",
  "realm": "saml1",
  "in_response_to": "4fee3b046395c4e751011e97f8900b5273d56685"
}
```

