# auth-action.js
> GitHub API token authentication for GitHub Actions
[](https://www.npmjs.com/package/@octokit/auth-action)
[](https://github.com/octokit/auth-action.js/actions?query=workflow%3ATest)
`@octokit/auth-action` is one of [GitHub’s authentication strategies](https://github.com/octokit/auth.js).
It does not require any configuration, but instead reads [the `GITHUB_TOKEN` environment variable](https://help.github.com/en/articles/virtual-environments-for-github-actions#github_token-secret) that is provided to GitHub Actions.
- [Usage](#usage)
- [`createActionAuth()`](#createactionauth)
- [`auth()`](#auth)
- [Authentication object](#authentication-object)
- [`auth.hook(request, route, options)` or `auth.hook(request, options)`](#authhookrequest-route-options-or-authhookrequest-options)
- [Find more information](#find-more-information)
- [License](#license)
## Usage
Install with npm install @octokit/auth-action
```js
const { createActionAuth } = require("@octokit/auth-action");
// or: import { createActionAuth } from "@octokit/auth-action";
const auth = createActionAuth();
const authentication = await auth();
// {
// type: 'token',
// token: 'v1.1234567890abcdef1234567890abcdef12345678',
// tokenType: 'oauth'
// }
```
## `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](https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token).
`GITHUB_TOKEN` can be passed as environment variable using [`env:`](https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#env)
```yml
steps:
- name: My action
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
or using [`with:`](https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstepswith)
```yml
steps:
- name: My action
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
or named `token` using [`with:`](https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstepswith)
```yml
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.
```yml
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 the authentication object.
## Authentication object
name | type | description |
---|---|---|
type
|
string
|
"token"
|
token
|
string
|
The provided token. |
tokenType
|
string
|
Can be either "oauth" for personal access tokens and OAuth tokens, or "installation" for installation access tokens (includes GITHUB_TOKEN provided to GitHub Actions)
|