# API-Auth Examples

**The main goal of these examples is to demonstrate how a** [**Task Developer**](https://devs.truebit.io/overview/how-do-you-intend-to-use-truebit#task-developers) **can create** [**Truebit API Tasks**](https://devs.truebit.io/developing-truebit-tasks/how-to-create-api-tasks) **that interact with authenticated endpoints.**

\
In this section, we’ll walk through how to handle each of the supported authentication methods: *custom-header, basic-auth*, and aws-signature.

### 1. Test Your Manifest

Use the  [`start-api`](https://devs.truebit.io/truebit-cli-reference#start-api) command to execute the API task locally within the context of the Truebit Node. This allows you to verify that the authenticated endpoints behave as expected.

#### custom-header

{% code overflow="wrap" %}

```bash
truebit start-api api-auth/custom-header/custom-header.manifest.json api-auth/custom-header/custom-header.input.json custom-header 'username:foo, password:bar'
```

{% endcode %}

**basic-auth**

{% code overflow="wrap" %}

```bash
truebit start-api api-auth/basic-auth/basic-auth.manifest.json api-auth/basic-auth/basic-auth.input.json basic-auth 'username:<username>,password:<password>'
```

{% endcode %}

**aws-signature**

{% code overflow="wrap" %}

```bash
truebit start-api api-auth/aws-signature/aws-signature.manifest.json api-auth/aws-signature/aws-signature.input.json aws-signature "accessKey:AKIA2VXUSRQO3CTJ5UH5,secretKey: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"
```

{% endcode %}

### 2. Create The Truebit API Task

Once the authenticated endpoints have been successfully tested, create the Truebit API Task by running the [`create-api`](https://devs.truebit.io/truebit-cli-reference#create-api) command.

#### custom-header

{% code overflow="wrap" %}

```bash
truebit create-api api-auth/custom-header/custom-header.manifest.json
```

{% endcode %}

**basic-auth**

{% code overflow="wrap" %}

```bash
truebit create-api api-auth/basic-auth/basic-auth.manifest.json
```

{% endcode %}

**aws-signature**

{% code overflow="wrap" %}

```bash
truebit create-api api-auth/aws-signature/aws-signature.manifest.json
```

{% endcode %}

### 3. Deploy the Truebit API Task

Deploy the created API Task using the [deploy](https://devs.truebit.io/truebit-cli-reference#deploy) command. This makes it available for execution by [Task Requesters](https://devs.truebit.io/overview/how-do-you-intend-to-use-truebit#task-requesters).

{% code overflow="wrap" %}

```bash
truebit deploy <namespace> <taskname> --taskId <taskId>
```

{% endcode %}

* \[taskId]: Add the taskId generated in step 2

### 4. Deploy the Authentication Credentials

After deploying the API Task, upload the required authentication credentials using the `api-auth` command. This ensures the Task Requester can execute the task without encountering authentication issues.

#### custom-header

{% code overflow="wrap" %}

```bash
truebit api-auth <namespace> <taskname> <taskId> custom-header "username:<username>,password:<password>"
```

{% endcode %}

**basic-auth**

{% code overflow="wrap" %}

```bash
truebit api-auth <namespace> <taskname> <taskId> basic-auth 'username:<username>,password:<password>'
```

{% endcode %}

**aws-signature**

{% code overflow="wrap" %}

```bash
truebit api-auth <namespace> <taskname> <taskId> aws-signature "accessKey:AKIA2VXUSRQO3CTJ5UH5,secretKey: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"
```

{% endcode %}

### 5. Execute The Truebit API Task

Now, you're ready to execute the Truebit API Task using the [execute-by-name](https://devs.truebit.io/integrating-truebit-tasks/api-task-execution/execute-api-tasks) endpoint and retrieve the Truebit transcript.
