> For the complete documentation index, see [llms.txt](https://bittu-1.gitbook.io/meshkit-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bittu-1.gitbook.io/meshkit-documentation/authentication.md).

# Authentication

MeshKit authenticates with the configured storage provider. The current provider implementation is Pinata and expects a Pinata JWT.

## Overview

Authentication is configured once when calling `Meshkit.init()`.

```ts
const meshkit = await Meshkit.init({
  provider: "pinata",
  providerToken: "PINATA_JWT",
});
```

The token is sent to Pinata using a Bearer authorization header.

```http
Authorization: Bearer PINATA_JWT
```

## Configuration

| Field           | Type                                   | Required | Description                                                                                     |
| --------------- | -------------------------------------- | -------- | ----------------------------------------------------------------------------------------------- |
| `provider`      | `"pinata" \| "filebase" \| "storacha"` | Yes      | Provider selector from the public type. The current implementation constructs `PinataProvider`. |
| `providerToken` | `string`                               | Yes      | Pinata JWT used for API authentication.                                                         |
| `gatewayUrl`    | `string`                               | No       | Custom IPFS gateway base URL. Defaults to `https://gateway.pinata.cloud/ipfs/`.                 |
| `keyService`    | `KeyService`                           | No       | Reserved by the type system. The current implementation does not use it.                        |

Planned, not yet implemented:

* Filebase provider authentication
* Storacha provider authentication

## Test Credentials

Use `testConnection()` after initialization to verify the token.

```ts
const meshkit = await Meshkit.init({
  provider: "pinata",
  providerToken: "PINATA_JWT",
});

const ok = await meshkit.testConnection();
```

`testConnection()` calls Pinata's authentication test endpoint and returns `true` when the response contains a success message.

## Security Guidance

* Do not commit Pinata JWTs to source control.
* Do not hardcode production tokens in client applications.
* Prefer platform-specific secure storage for mobile applications.
* Use a restricted Pinata token where possible.
* Treat CIDs as public identifiers. Anyone with gateway access and the CID may be able to fetch unencrypted content.

## Current Limitations

The `keyService`, `encrypt`, and `decrypt` fields are present in the TypeScript types but are not applied by the current MeshKit implementation. Do not assume automatic encryption until the implementation explicitly supports it.

## Related APIs

* [init()](/meshkit-documentation/api/init.md)
* [testConnection()](/meshkit-documentation/api/testconnection.md)
* [Error Handling](/meshkit-documentation/error-handling.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://bittu-1.gitbook.io/meshkit-documentation/authentication.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
