# octokit-from-auth

> Creates a GitHub Octokit instance from any available auth token. 🐙

Latest version **0.3.2** (published 2025-05-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install octokit-from-auth
pnpm add octokit-from-auth
yarn add octokit-from-auth
bun add octokit-from-auth
```

## Health

**Score 60/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; has provenance; high maintenance score; high quality score.

Warnings: low downloads; pre 1.0.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 0.3.2 |
| Published | 2025-05-27 |
| First published | 2024-12-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18.3.0 |
| Dependencies | 2 |
| Unpacked size | 9.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 2 |
| Author | Josh Goldberg ✨ |
| Maintainers | joshuakgoldberg |

## Links

- npm: https://www.npmjs.com/package/octokit-from-auth
- Repository: https://github.com/JoshuaKGoldberg/octokit-from-auth
- Homepage: https://github.com/JoshuaKGoldberg/octokit-from-auth#readme
- Issues: https://github.com/JoshuaKGoldberg/octokit-from-auth/issues
- npm.io page: https://npm.io/package/octokit-from-auth

## Dependencies (2)

- [octokit](https://npm.io/package/octokit.md) ^5.0.0
- [get-github-auth-token](https://npm.io/package/get-github-auth-token.md) ^0.1.0

## Recent versions

- 0.3.2 (latest) — 2025-05-27
- 0.3.1 — 2025-04-01
- 0.3.0 — 2024-12-16
- 0.2.0 — 2024-12-15
- 0.1.0 — 2024-12-15

## README

<h1 align="center">Octokit From Auth</h1>

<p align="center">
	Creates a GitHub Octokit instance from any available auth token.
	🐙
</p>

<p align="center">
	<!-- prettier-ignore-start -->
	<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
	<a href="#contributors" target="_blank"><img alt="👪 All Contributors: 1" src="https://img.shields.io/badge/%F0%9F%91%AA_all_contributors-1-21bb42.svg" /></a>
<!-- ALL-CONTRIBUTORS-BADGE:END -->
	<!-- prettier-ignore-end -->
	<a href="https://github.com/JoshuaKGoldberg/octokit-from-auth/blob/main/.github/CODE_OF_CONDUCT.md" target="_blank"><img alt="🤝 Code of Conduct: Kept" src="https://img.shields.io/badge/%F0%9F%A4%9D_code_of_conduct-kept-21bb42" /></a>
	<a href="https://codecov.io/gh/JoshuaKGoldberg/octokit-from-auth" target="_blank"><img alt="🧪 Coverage" src="https://img.shields.io/codecov/c/github/JoshuaKGoldberg/octokit-from-auth?label=%F0%9F%A7%AA%20coverage" /></a>
	<a href="https://github.com/JoshuaKGoldberg/octokit-from-auth/blob/main/LICENSE.md" target="_blank"><img alt="📝 License: MIT" src="https://img.shields.io/badge/%F0%9F%93%9D_license-MIT-21bb42.svg" /></a>
	<a href="http://npmjs.com/package/octokit-from-auth" target="_blank"><img alt="📦 npm version" src="https://img.shields.io/npm/v/octokit-from-auth?color=21bb42&label=%F0%9F%93%A6%20npm" /></a>
	<img alt="💪 TypeScript: Strict" src="https://img.shields.io/badge/%F0%9F%92%AA_typescript-strict-21bb42.svg" />
</p>

## Usage

```shell
npm i octokit-from-auth
```

Two functions are exported by the `octokit-from-auth` package.
Both are asynchronous and take in the same constructor parameters as the [`Octokit` class](https://github.com/octokit/octokit.js?tab=readme-ov-file#octokit-api-client):

- `octokitFromAuth`: rejects if an auth token isn't provided and can't be resolved by [`get-github-auth-token`](https://github.com/JoshuaKGoldberg/get-github-auth-token)
- `octokitFromAuthSafe`: resolves an `Octokit` with no authentication if an auth token isn't provided and can't be resolved by [`get-github-auth-token`](https://github.com/JoshuaKGoldberg/get-github-auth-token)

Both return a new Octokit instance.

```ts
import { octokitFromAuth } from "octokit-from-auth";

// auth token used:
// process.env.GH_TOKEN ?? (await $`gh auth token`)
await octokitFromAuth();
```

The Octokit's `auth` is retrieved with [`get-github-auth-token`](https://github.com/JoshuaKGoldberg/get-github-auth-token), which defaults to `process.env.GH_TOKEN`, or failing that, [`gh auth token`](https://cli.github.com/manual/gh_auth_token).
If neither is available then an auth token must be provided as an option:

```ts
import { octokitFromAuth } from "octokit-from-auth";

// auth token used:
// "gho_..."
await octokitFromAuth({ auth: "gho_..." });
```

## Development

See [`.github/CONTRIBUTING.md`](./.github/CONTRIBUTING.md), then [`.github/DEVELOPMENT.md`](./.github/DEVELOPMENT.md).
Thanks! 🐙

## Contributors

<!-- spellchecker: disable -->
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
  <tbody>
    <tr>
      <td align="center"><a href="http://www.joshuakgoldberg.com/"><img src="https://avatars.githubusercontent.com/u/3335181?v=4?s=100" width="100px;" alt="Josh Goldberg ✨"/><br /><sub><b>Josh Goldberg ✨</b></sub></a><br /><a href="https://github.com/JoshuaKGoldberg/octokit-from-auth/commits?author=JoshuaKGoldberg" title="Code">💻</a> <a href="#content-JoshuaKGoldberg" title="Content">🖋</a> <a href="https://github.com/JoshuaKGoldberg/octokit-from-auth/commits?author=JoshuaKGoldberg" title="Documentation">📖</a> <a href="#ideas-JoshuaKGoldberg" title="Ideas, Planning, & Feedback">🤔</a> <a href="#infra-JoshuaKGoldberg" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#maintenance-JoshuaKGoldberg" title="Maintenance">🚧</a> <a href="#projectManagement-JoshuaKGoldberg" title="Project Management">📆</a> <a href="#tool-JoshuaKGoldberg" title="Tools">🔧</a></td>
    </tr>
  </tbody>
</table>

<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->

<!-- ALL-CONTRIBUTORS-LIST:END -->
<!-- spellchecker: enable -->

> 💝 This package was templated with [`create-typescript-app`](https://github.com/JoshuaKGoldberg/create-typescript-app) using the [Bingo framework](https://create.bingo).

---
_Source: https://npm.io/package/octokit-from-auth · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
