# Authentication

### [OAuth 2.0 Password Grant](https://oauth.net/2/grant-types/password/)

Request

{% tabs %}
{% tab title="cURL" %}

```bash
curl --location --request POST 'https://api.butlr.io/api/v2/login' \
--header 'Content-Type: application/json' \
--data-raw '{
    "username": "your@email.com",
    "password": "your_password"
}'
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://api.butlr.io/api/v2/login"
  method := "POST"

  payload := strings.NewReader(`{
    "username": "your@email.com",
    "password": "your_password"
}`)

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
    return
  }
  req.Header.Add("Content-Type", "application/json")

  res, err := client.Do(req)
  if err != nil {
    fmt.Println(err)
    return
  }
  defer res.Body.Close()

  body, err := ioutil.ReadAll(res.Body)
  if err != nil {
    fmt.Println(err)
    return
  }
  fmt.Println(string(body))
}
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
import json

url = "https://api.butlr.io/api/v2/login"

payload = json.dumps({
  "username": "your@email.com",
  "password": "your_password"
})
headers = {
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
```

{% endtab %}
{% endtabs %}

Response

```json
{
    "access_token": "your_access_token",
    "refresh_token": "your_refresh_token",
    "id_token": "your_id_token",
    "scope": "your_scopes",
    "expires_in": 1000,
    "token_type": "Bearer"
}
```

### [OAuth 2.0 Client Credentials Grant](https://oauth.net/2/grant-types/client-credentials/)

#### How to create your client credentials

1. Go to the [Butlr Web App](https://app.butlr.io).
2. Sign in using your username and password.
3. Click the expandable menu (v) in the top navigation bar (upper right corner) and select **Account Settings**.

<figure><img src="https://3289302098-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fe3YixUK5tCcflJxye0bT%2Fuploads%2Fgit-blob-ff9395628ea42cc6badb097b5f4e154ed5673cc3%2Fnav-account-setting-gif.gif?alt=media" alt=""><figcaption></figcaption></figure>

4. Navigate to the **API tokens** tab.
5. Click the **Create token** button.
6. Enter a **Name** and a **Description**, then click **Create**.
7. A dialog box will display your **Client ID** and **Client Secret**.

<figure><img src="https://3289302098-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fe3YixUK5tCcflJxye0bT%2Fuploads%2Fgit-blob-6b9c1af3ece361f38ae86e05058ca4f526abf823%2Fcreate-token.gif?alt=media" alt=""><figcaption></figcaption></figure>

* ⚠️ Important: Be sure to copy and securely store these credentials. For security reasons, they will not be shown again after you close the dialog.

Request

{% tabs %}
{% tab title="cURL" %}

```bash
curl --location --request POST 'https://api.butlr.io/api/v2/clients/login' \
--header 'Content-Type: application/json' \
--data '{
    "client_id": "your_client_id",
    "client_secret": "your_client_secret",
    "audience": "https://butlrauth/",
    "grant_type": "client_credentials"
}'
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://api.butlr.io/api/v2/clients/login"
  method := "POST"

  payload := strings.NewReader(`{
    "client_id": "your_client_id",
    "client_secret": "your_client_secret",
    "audience": "https://butlrauth/",
    "grant_type": "client_credentials"
}`)

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
    return
  }
  req.Header.Add("Content-Type", "application/json")

  res, err := client.Do(req)
  if err != nil {
    fmt.Println(err)
    return
  }
  defer res.Body.Close()

  body, err := ioutil.ReadAll(res.Body)
  if err != nil {
    fmt.Println(err)
    return
  }
  fmt.Println(string(body))
}
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
import json

url = "https://api.butlr.io/api/v2/clients/login"

payload = json.dumps({
  "client_id": "your_client_id",
  "client_secret": "your_client_secret",
  "audience": "https://butlrauth/",
  "grant_type": "client_credentials"
})
headers = {
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
```

{% endtab %}
{% endtabs %}

**Response**

```json
{
    "access_token": "your_access_token",
    "scope": "your_scopes",
    "expires_in": 1000,
    "token_type": "Bearer"
}
```
