> For the complete documentation index, see [llms.txt](https://developers.neowit.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.neowit.io/rest-api/authentication/basic-auth.md).

# Basic Auth

## Overview

Basic Auth is supported in most request libraries and is often as simple as adding a username- and password parameter. To get you up and running quickly, we present a few language-specific methods by fetching a list of projects available from the REST API using a [Service Account](/service-accounts/creating-service-accounts.md) for access control.

{% hint style="info" %}
We don't recommend using this authentication flow for production use, the main use for Basic Auth is for quick exploration and experimentation.
{% endhint %}

{% hint style="warning" %}
Basic Auth only works with legacy `HS256` Service Account keys that have a shared secret. It is not supported for `RS256` keys. If the key has an expiration date, Basic Auth stops working when the key expires.
{% endhint %}

## Prerequisites

A [Service Account](/service-accounts/creating-service-accounts.md) with a non-expired `HS256` key must be created in the organization before continuing.

## Code Sample

The following examples send a GET request to list available spaces in your organization. See the API Reference for all available API calls.

{% tabs %}
{% tab title="Python" %}
{% code lineNumbers="true" %}

```python
import requests  # pip install requests

# Inputs
key_id = '<service account key id>'
secret = '<service account secret>'

if __name__ == '__main__':
    # Send GET request to endpoint of choice with Basic Auth authentication.
    spaces = requests.get(
        url='https://app.neowit.io/api/space/v1/space',
        auth=(key_id, secret),
    )

    # Print response contents.
    print(spaces.json())
```

{% endcode %}
{% endtab %}

{% tab title="Node.js" %}
{% code lineNumbers="true" %}

```javascript
// modules
const axios = require('axios').default; // npm install axios

// Inputs
const keyID = '<service account key id>';
const secret = '<service account secret>';

async function main() {
    // Send GET request to endpoint of choice with Basic Auth authentication.
    const response = await axios({
        method: 'GET',
        url: 'https://app.neowit.io/api/space/v1/space',
        auth: {
            username: keyID,
            password: secret,
        },
    });

    // Print response contents.
    console.log(JSON.stringify(response.data, null, 2));
}
main();
```

{% endcode %}
{% endtab %}

{% tab title="Go" %}
{% code lineNumbers="true" %}

```go
package main

import (
	"encoding/json"
	"fmt"
	"log"
	"net/http"
	"time"
)

const (
	spacesURL = "https://app.neowit.io/api/space/v1/space"
	keyID     = "<service account key id>"
	secret    = "<service account secret>"
)

func main() {
	// Create a custom http Client with timeout.
	client := &http.Client{Timeout: time.Second * 3}

	// Create the request object with method, URL, but no optional body.
	req, err := http.NewRequest("GET", spacesURL, nil)
	if err != nil {
		log.Fatal(err)
	}

	// Set the request's Authorization header to use HTTP Basic Authentication.
	req.SetBasicAuth(keyID, secret)

	// Send an HTTP request and return an HTTP response.
	response, err := client.Do(req)
	if err != nil {
		log.Fatal(err)
	}
	defer response.Body.Close()

	// Convert response body to map.
	var body map[string]interface{}
	if err = json.NewDecoder(response.Body).Decode(&body); err != nil {
		log.Fatal(err)
	}

	// Pretty print the response body.
	prettyBody, _ := json.MarshalIndent(body, "", "    ")
	fmt.Println(string(prettyBody))
}

```

{% endcode %}
{% endtab %}

{% tab title="cURL" %}

```bash
export NW_SERVICE_ACCOUNT_KEY_ID="<service account key id>"
export NW_SERVICE_ACCOUNT_SECRET="<service account secret>"

curl -X GET "https://app.neowit.io/api/space/v1/space" \
    -H "accept: application/json" \
    -u $NW_SERVICE_ACCOUNT_KEY_ID:$NW_SERVICE_ACCOUNT_SECRET
```

{% endtab %}
{% endtabs %}
