Skip to content

Commit

Permalink
docs: improve authorization docs
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias authored Nov 23, 2023
1 parent f326cee commit 5fc5592
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ const client = create(new URL('http://127.0.0.1:5002'))
const { cid } = await client.add('Hello world!')
```

Do you use Kubo's [**`API.Authorizations`**](https://github.com/ipfs/kubo/blob/master/docs/config.md#apiauthorizations)? Check the [Custom Headers](#custom-headers) section.

### API

`kubo-rpc-client` will not implement the [IPFS Core API](https://github.com/ipfs/js-ipfs/tree/master/docs/core-api). Please see <https://github.com/ipfs/kubo/issues/9125> for more information.
Expand Down Expand Up @@ -346,15 +348,33 @@ const ipfs = window.KuboRpcClient.create()

### Custom Headers

If you wish to send custom headers with each request made by this library, for example, the Authorization header. You can use the config to do so:
If you wish to send custom headers with each request made by this library, for example, the `Authorization` header. This can be useful if your Kubo node has keys defined in [`API.Authorizations`](https://github.com/ipfs/kubo/blob/master/docs/config.md#apiauthorizations).

If you're using `bearer:token`, where `token` is `abc123`:

```js
const ipfs = create({
host: 'localhost',
port: 5001,
protocol: 'http',
headers: {
authorization: 'Bearer abc123'
}
})
```

If you're using `basic:user:password`, where `user:password` is `alice:secret`:

```js
const ipfs = create({
host: 'localhost',
port: 5001,
protocol: 'http',
headers: {
authorization: 'Bearer ' + TOKEN
// For Node.js, using:
// Buffer.from('alice:secret').toString('base64')
// is preferred over using `btoa`.
authorization: 'Basic ' + btoa('alice:secret')
}
})
```
Expand Down

0 comments on commit 5fc5592

Please sign in to comment.