Personal Access Token
Personal Access Tokens (PATs)
A Personal Access Token (PAT) is used to authenticate with GitHub in place of a password — for example, when pulling private packages, publishing packages, or using the GitHub API from scripts and CI/CD pipelines.
GitHub offers two types of PATs:
Token Types
Fine-grained Tokens (recommended for most tasks)
Fine-grained tokens are the newer, more secure token format introduced by GitHub. They offer:
- Repository-scoped access — you select exactly which repositories the token can access, rather than granting access to everything.
- Granular permissions — instead of broad scopes (e.g.
repo), you choose specific read/write permissions per resource (Issues, Pull Requests, Contents, etc.). - Expiry enforcement — fine-grained tokens require an expiry date (maximum 1 year).
- Owner approval — if your organisation enforces it, tokens may require admin approval before they become active.
Fine-grained tokens are ideal for:
- Accessing or cloning specific repositories
- Operating GitHub Actions with least-privilege access
- Anything where limiting blast radius is important
Limitation: Fine-grained tokens cannot currently authenticate against the GitHub Packages / npm registry. If your task involves installing or publishing packages, you must use a Classic token.
Classic Tokens (required for GitHub Packages)
Classic tokens use a broad, scope-based permission model and have been available since GitHub's early API days. While less granular than fine-grained tokens, they are currently the only supported token type for GitHub Packages authentication.
When you must use a Classic token
| Use Case | Classic Token Required? |
|---|---|
npm install / yarn install from a private GitHub Package registry | ✅ Yes |
Publishing a package to GitHub Packages (npm publish) | ✅ Yes |
| Reading/installing packages in CI/CD (e.g. GitHub Actions, local dev) | ✅ Yes |
| General GitHub API access or repository operations | ❌ Fine-grained preferred |
Required scopes for package work
When creating a Classic token for package consumption or development, select the following scopes:
| Scope | Purpose |
|---|---|
read:packages | Download / install packages from the GitHub Package Registry |
write:packages | Publish packages to the GitHub Package Registry |
repo | Required when the package repository is private — allows the registry to verify access |
delete:packages | (Optional) Remove package versions you own |
Tip: If you only need to consume (install) packages and not publish them,
read:packages+repois sufficient. Only addwrite:packagesif you are actively developing and publishing packages.
How to Create a Classic Token
This is the token type you will need for local development and CI/CD package access.
- Go to GitHub Tokens (Classic) — ensure you are logged into the correct account.
- Give the token a descriptive Note, e.g.
Package DevelopmentorPackage Read-Only. - Set an Expiration — choose an appropriate window (e.g. 90 days). Avoid "No expiration" for security reasons.
- Under Select scopes, tick the scopes relevant to your use case (see table above).
- Click Generate token and copy it immediately — GitHub will not show it again.
How to Create a Fine-grained Token
- Go to GitHub Fine-grained Tokens — ensure you are logged into the correct account.
- Give the token a descriptive Token name.
- Set an Expiration (required — up to 365 days).
- Under Resource owner, select the organisation or your personal account.
- Under Repository access, choose Only select repositories and pick the repositories needed.
- Under Permissions, expand each section and set only the minimum permissions required.
- Click Generate token and copy it immediately.
Configuring projects to use tokens
This setup works for both local development and CI/CD pipelines.
- Configure projects to use tokens in the
.npmrcor.yarnrc.ymlfiles. - Set the
NODE_AUTH_TOKENenvironment variable to your Classic token when applicable in:- GitHub Repository Secrets for CI/CD pipelines
- User Account System environment variables for local development.
1. For Yarn Projects
Once you have a Classic token, configure npm to authenticate against the GitHub Package Registry by adding the following to the project-level .yarnrc.yml:
npmScopes:
es-profiler:
npmAlwaysAuth: false
npmAuthToken: ${NODE_AUTH_TOKEN:-}
npmRegistryServer: "https://npm.pkg.github.com"
1. For NPM Projects
Once you have a Classic token, configure npm to authenticate against the GitHub Package Registry by adding the following to the project-level .npmrc:
//npm.pkg.github.com/:_authToken=${NODE_AUTH_TOKEN}
@es-profiler:registry=https://npm.pkg.github.com
2. For Local Development
Never commit your token to source control. Use environment variables or secrets management instead. In CI/CD pipelines, store the token as a secret (e.g.
GITHUB_TOKENor a custom secret) and reference it in yournpmrcvia${TOKEN_ENV_VAR}.
Best Practices
- Rotate tokens regularly — set a calendar reminder before your token expires.
- Use the minimum required scopes — avoid
repoon Classic tokens unless the package repository is private. - Revoke unused tokens — audit your tokens periodically at github.com/settings/tokens.
- Never share tokens — each developer and each CI/CD pipeline should have its own token.
- Prefer fine-grained tokens for any non-package GitHub API usage.

