GitHub: 401 "Bad credentials"
The GitHub API does not accept the token at all. It has expired or been revoked, or it was never a token for this GitHub. From GitHub's Token expiration and revocation: an expired or revoked token can no longer be used, and it cannot be restored; you need a new token. Unlike a 403 ("Resource not accessible by personal access token"), changing the token's permissions will not fix this.
The whole answer
A real one (from a public report):
HTTP 401
{"message": "Bad credentials",
"documentation_url": "https://docs.github.com/rest",
"status": "401"}
GitHub does not fall back to reading anonymously. In that report the calls read public repositories, which work without any token, and failed the same way. To check the token alone:
curl -i -H "Authorization: Bearer your-token" https://api.github.com/user
A token that GitHub accepts answers 200 with your account. For GitHub Enterprise Server, call your server's API address instead of api.github.com.
Why a token stops working
From GitHub's Token expiration and revocation:
- Expiration date: when a personal access token reaches its expiration date, it is revoked automatically.
- A year without use: GitHub automatically revokes a personal access token or an OAuth token that has not been used in one year.
- Pushed to a public repository or gist: a valid token that is pushed to a public repository or a public gist is revoked automatically.
- Deleted: you, or for managed accounts an enterprise owner, deleted it. Enterprise owners can also revoke a token's single sign-on authorization; that gives "Resource protected by organization SAML enforcement" instead.
The same page notes that an expired or revoked token may leave an oauth_authorization.destroy action in your security log, which tells you when.
Two more causes are on your side: the token was mistyped or cut short when pasted, or it was made on another GitHub. A github.com token means nothing to a GitHub Enterprise Server, and the other way round.
Create a new token
- Your profile picture, Settings, Developer settings, Personal access tokens, Fine-grained tokens, Generate new token.
- The same resource owner, repositories and permissions as the old one, and an expiration. A link can open the form filled in, for example
https://github.com/settings/personal-access-tokens/new?name=IDE&expires_in=90&pull_requests=write&contents=write&statuses=read. From GitHub's pre-filling a token:expires_inis 1 to 366 days ornone, and without it the token expires in 30 days, or sooner if the organization has a token lifetime policy. - Generate token, copy it, and if the organization requires approval, wait for it.
- Put it everywhere the old one was.
In IntelliJ IDEA: "Incorrect credentials." and "User authorization failed"
The GitHub support built into IntelliJ IDEA checks a token by reading the account with it: GET /user, the same call as the curl above. A 401, and also a 402 or a 403 that is not about the rate limit, counts as a failed login. In the source (checked October 30, 2026; IntelliJ IDEA: GHTokenCredentialsUi.kt, GithubApiRequestExecutor.kt, GHSecurityUtil.kt, GHSelectorErrorStatusPresenter.kt, GHAPIExceptionUtil.kt, GHAccountsUtil.kt):
- When you log in with a token: "Incorrect credentials." and, on the next line, "Request response: Bad credentials.", the second part being GitHub's own message. It does not say which of the causes above it is.
- The token field says "The following scopes must be granted to the access token:" with
repo,gist,read:org,workflow,read:useranduser:email. Its Generate… button openssettings/tokens/newon the same server with these scopes and the description "IntelliJ IDEA GitHub integration plugin" (with your IDE's name) filled in: the form for a personal access token (classic), the kind with scopes, not the fine-grained token of the steps above. - In the Pull Requests tool window, when GitHub refuses the saved token as the window connects to a repository: "Could not connect to repository … with account …" and "User authorization failed", without GitHub's message, and Log in again….
- Logging in again keeps the account's server. For github.com it first asks "Log in to GitHub to continue", with Log In via GitHub… or Use Token…; for GitHub Enterprise it opens the token login straight away.
GitHub pull requests in IntelliJ IDEA
Pull Request Inbox for GitHub, a plugin by Lesstep for JetBrains IDEs 2024.1 or later, keeps one token for github.com and one for your GitHub Enterprise, each in the IDE's password safe and sent only to its own host. When GitHub answers 401, the plugin says that the token expired, was revoked or is from another host, shows GitHub's message, and offers to open its settings, which link to GitHub's new-token page. The review inbox, diffs and conversations are free; approving, commenting and merging are Pro (US$1.50 a month, with a 30-day trial).
GitHub is a trademark of GitHub, Inc.; IntelliJ IDEA is a trademark of JetBrains s.r.o. This page is not affiliated with or endorsed by GitHub, Inc. or JetBrains.
More: "Resource not accessible by personal access token" · "Resource protected by organization SAML enforcement" · "API rate limit exceeded" · GitHub merge refused (405, 409) · GitHub review refused (422) · GitHub search 422 "Validation Failed" · GitHub diff 406 "too_large", 3,000 files · GitHub line comment 422 "must be part of the diff" · GitHub branch update refused (422) · GitHub pull request not created (422, 403) · GitHub auto-merge refused · GitHub draft, ready for review or close refused · GitHub conversation not resolved · GitHub checks not shown (check runs 403) · GitHub file contents not read · GitHub compare refused (404, 422) · GitHub comment or reply refused (403 locked, archived) · GitHub merge method not allowed (405) · GitHub branch not found (404, 301) · GitHub Enterprise Server not reached · GitHub review request not shown · GitHub pull request list incomplete · GitHub 404 Not Found, renamed repositories (301, 307) · GitHub line comment outdated or not on the diff · GitHub pull requests not updating, notifications late · GitHub suggested change cannot be applied · GitHub required check stuck at "Expected" · GitHub code owner review required · GitHub merge blocked by unresolved conversations · GitHub merge blocked by unsigned commits · GitHub branch that merges through a merge queue · GitHub merge waiting for an approval of the most recent push · GitHub merge waiting for code scanning results · GitHub merge waiting for code quality results · GitHub merge blocked by a code coverage threshold · GitHub merge blocked by license compliance results · GitHub branch locked or its updates restricted · GitHub branch not deleted after merging · GitHub merge waiting for a team's approval (Required reviewers) · GitHub merge blocked by secret scanning alerts · GitHub stacked pull request not merging · GitHub push blocked by push rules · GitHub merge blocked by commit metadata rules · GitHub force push blocked · GitHub issue not closed by a merged pull request · GitHub pull request not checked out locally · GitHub pull request has merge conflicts · GitHub changes requested and dismissing a review · GitHub co-author not credited for a commit · GitHub dependency review check failed · GitHub Dependabot not rebasing its pull request · GitHub fork not syncing with upstream · GitHub pull request base branch not changing · GitHub pull request not reverting · GitHub pull request template not showing · GitHub pull request labels or assignees not added · GitHub pull request not closing or reopening · GitHub push blocked by push protection · GitHub pull request comment hidden · GitHub pull request blocked until deployments succeed · GitHub team review request replaced by members · GitHub pull request file no longer marked Viewed · GitHub pull request marked merged without being merged · GitHub Copilot review does not count as an approval · GitHub checks not running on a pull request a workflow created · GitHub Update branch button not shown on a pull request · GitHub checks failing on a Dependabot pull request · GitHub checks failing on a pull request from a fork · GitHub checks skipped by [skip ci] in a commit message · GitHub checks gone after the retention period · GitHub code review limits in a public repository · GitHub pull requests turned off or limited in a repository · GitHub checks run on every pull request in a stack · GitHub pull request showing commits already squash merged · GitHub pull request not showing a file diff · GitHub push to a pull request branch from a fork refused · GitHub check cancelled on a pull request · GitHub Rebase and merge not available · GitHub merge commit message not what you expected · GitHub pull request shows every line changed · GitHub API request timed out · GitHub pull request image or document diff not shown · GitHub review request refused (422) · GitHub pull request from Copilot: checks not running, approval not counted · GitHub push refused: GH006 and GH013 on a protected branch · GitHub "At least 1 approving review is required", approvals that do not count · GitHub pull request plugins for IntelliJ IDEA, compared · 日本語