npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@octokit/auth-action

v5.1.1

Published

GitHub API token authentication for GitHub Actions

Downloads

205,455

Readme

auth-action.js

GitHub API token authentication for GitHub Actions

@latest Build Status

@octokit/auth-action is one of GitHub’s authentication strategies.

It does not require any configuration, but instead reads the GITHUB_TOKEN environment variable that is provided to GitHub Actions.

Usage

Install with npm install @octokit/auth-action

import { createActionAuth } from "@octokit/auth-action";

const auth = createActionAuth();
const authentication = await auth();
// {
//   type: 'token',
//   token: 'v1.1234567890abcdef1234567890abcdef12345678',
//   tokenType: 'oauth'
// }

[!IMPORTANT] As we use conditional exports, you will need to adapt your tsconfig.json by setting "moduleResolution": "node16", "module": "node16".

See the TypeScript docs on package.json "exports". See this helpful guide on transitioning to ESM from @sindresorhus

createActionAuth()

The createActionAuth() method has no options.

It expects the GITHUB_TOKEN variable to be set which is provided to GitHub Actions, but has to be configured explicitly.

GITHUB_TOKEN can be passed as environment variable using env:

steps:
  - name: My action
    env:
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

or using with:

steps:
  - name: My action
    with:
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

or named token using with:

steps:
  - name: My action
    with:
      token: ${{ secrets.GITHUB_TOKEN }}

GITHUB_TOKEN can be set to any of the repository's secret, e.g. if you want to use a personal access token.

steps:
  - name: My first action
    env:
      GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

createActionAuth() is also checking for the GITHUB_ACTION variable to be present to make sure that it runs within a GitHub Action.

If GITHUB_ACTION or neither GITHUB_TOKEN, INPUT_GITHUB_TOKEN or INPUT_TOKEN are set an error is thrown.

auth()

The auth() method has no options. It returns a promise which resolves with the authentication object.

Authentication object

auth.hook(request, route, options) or auth.hook(request, options)

auth.hook() hooks directly into the request life cycle. It authenticates the request using the provided token.

The request option is an instance of @octokit/request. The route/options parameters are the same as for the request() method.

auth.hook() can be called directly to send an authenticated request

const { data: authorizations } = await auth.hook(
  request,
  "GET /authorizations",
);

Or it can be passed as option to request().

const requestWithAuth = request.defaults({
  request: {
    hook: auth.hook,
  },
});

const { data: authorizations } = await requestWithAuth("GET /authorizations");

Find more information

auth() does not send any requests, it only retrieves the token from the environment variable and transforms the provided token string into an authentication object.

The GITHUB_TOKEN provided to GitHub Actions is an installation token with all permissions provided. You can use it for git commands, too. Learn more about the differences in token authentication at @octokit/auth-action.

License

MIT