---
type: api
title: Authenticate a user
description: Authenticates a user and returns information about the authenticated user.
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/operation/operation-security-authenticate
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/operation/operation-security-authenticate
products:
  - Elasticsearch
---

# Authenticate a user

Availability: 5.5+

## Paths

- `GET` `/_security/_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

Authenticates a user and returns information about the authenticated user.
Include the user information in a [basic auth header](https://en.wikipedia.org/wiki/Basic_access_authentication).
A successful call returns a JSON structure that shows user information such as their username, the roles that are assigned to the user, any assigned metadata, and information about the realms that authenticated and authorized the user.
If the user cannot be authenticated, this API returns a 401 status code.

## Response

`application/json`

- `api_key` ({} AuthenticateApiKey)
  - `id` (string Id)
  - `name` (string Name)
  - `managed_by` (enum CredentialManagedBy)
    Values: `cloud`, `elasticsearch`
  - `internal` (boolean)
- `authentication_realm` ({} RealmInfo)
  - `name` (string Name)
  - `type` (string)
- `email` (union string) — nullable
  One of: `string`
- `full_name` (union Name | string) — nullable
- `lookup_realm` ({} RealmInfo)
  - `name` (string Name)
  - `type` (string)
- `metadata` (Metadata)
- `roles` ([] string)
- `username` (string)
- `enabled` (boolean)
- `authentication_type` (string)
- `token` ({} Token)
  - `name` (string Name)
  - `type` (string)
  - `managed_by` (enum CredentialManagedBy)
    Values: `cloud`, `elasticsearch`
## Code Examples

#### Console

```console
GET /_security/_authenticate
```

#### JavaScript

```javascript
const response = await client.security.authenticate();
```

#### Python

```python
resp = client.security.authenticate()
```

#### curl

```curl
curl -X GET "$ELASTICSEARCH_URL/_security/_authenticate" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY"
```

#### Java

```java
client.security().authenticate();
```

#### C#

```c#
var response = await client.Security.AuthenticateAsync();
```

#### PHP

```php
$resp = $client->security()->authenticate();
```

#### Ruby

```ruby
response = client.security.authenticate
```

## Response Examples

#### Security authenticate response example1

A successful response from `GET /_security/_authenticate`.

```json
{
  "username": "rdeniro",
  "roles": [
    "admin"
  ],
  "full_name": null,
  "email":  null,
  "metadata": { },
  "enabled": true,
  "authentication_realm": {
    "name" : "file",
    "type" : "file"
  },
  "lookup_realm": {
    "name" : "file",
    "type" : "file"
  },
  "authentication_type": "realm"
}
```

#### Security authenticate response example2

A successful response from `GET /_security/_authenticate` for access token authentication.

```json
{
  "username": "0000000001",
  "roles": [
    "admin"
  ],
  "full_name": "Peter Parker",
  "email": "spider-man@marvel.com",
  "metadata": {},
  "enabled": true,
  "authentication_realm": {
    "name": "cloud-saml-kibana",
    "type": "saml"
  },
  "lookup_realm": {
    "name": "cloud-saml-kibana",
    "type": "saml"
  },
  "authentication_type": "token",
  "token": {
    "managed_by": "cloud"
  }
}
```

#### Security authenticate response example3

A successful response from `GET /_security/_authenticate` for service account token authentication.

```json
{
  "username": "elastic/fleet-server",
  "roles": [ ],
  "full_name": "Service account - elastic/fleet-server",
  "email": null,
  "metadata": {
    "_elastic_service_account": true
  },
  "enabled": true,
  "authentication_realm": {
    "name": "_service_account",
    "type": "_service_account"
  },
  "lookup_realm": {
    "name": "_service_account",
    "type": "_service_account"
  },
  "authentication_type": "token",
  "token": {
    "type": "_service_account_index",
    "name": "token_abcd1234",
    "managed_by": "elasticsearch"
  }
}
```

